C-chat
Functions | Variables
client.c File Reference

Client file. More...

#include "../common/packets.h"
#include <string.h>
#include <stdlib.h>
#include "ui.h"
#include "client.h"
#include "commands.h"
#include "../common/files.h"
#include <stdio.h>
#include "file-transfer.h"
#include "room.h"

Functions

THREAD_ENTRY_POINT sendMessage (void *data)
 An entry point for a thread that gets user input and send it to server. More...
 
 COMMAND_HANDLER (command, COMMAND(file, "Usage: /file <send | receive>", COMMAND(send, "Usage: /file send <filepath>", if(strlen(command) > 0) { sendFileUploadRequest(command);return;}) COMMAND(receive, "Usage: /file receive <id>", if(strlen(command) > 0) { long id=strtol(command, NULL, 10);if(id > 0) { sendFileDownloadRequest(id);return;} })) COMMAND(nick, "Usage: /nick <username>", if(strlen(command) > 0) { setUsername(command);return;}) COMMAND(quit, "Usage: /quit", Packet quitPacket=NewPacketQuit;sendPacket(clientSocket, &quitPacket);return;) COMMAND(room, "Usage: /room <create | join | leave | list>", COMMAND(create, "Usage: /room create <name> <description>", if(strlen(command) > 0) { createRoom(command);return;}) COMMAND(join, "Usage: /room join <name>", if(strlen(command) > 0) { joinRoom(command);return;}) COMMAND(leave, "Usage: /room leave", leaveRoom();return;) COMMAND(list, "Usage: /room list", listRooms();return;)))
 
void pickUsername ()
 
void setUsername (const char *newUsername)
 Notifies the server of username change. More...
 
int main ()
 Program entry. More...
 

Variables

Socket clientSocket
 
struct UploadData uploadData [MAX_CONCURRENT_FILE_TRANSFER]
 
struct DownloadData downloadData [MAX_CONCURRENT_FILE_TRANSFER]
 

Detailed Description

Client file.

Allows connection to a server and sending messages to another client.

Function Documentation

◆ main()

int main ( )

Program entry.

Returns
EXIT_SUCCESS - normal program termination.

◆ sendMessage()

THREAD_ENTRY_POINT sendMessage ( void *  data)

An entry point for a thread that gets user input and send it to server.

Gets user input and sent it to the server in an appropriate way.

Parameters
dataa NULL pointer
Returns
never

◆ setUsername()

void setUsername ( const char *  username)

Notifies the server of username change.

The server can reject the new username.

Parameters
usernameThe new username to use