Added system messages to client and added welcome message from server.
This commit is contained in:
parent
a1b1b80449
commit
81fc72a1d7
|
@ -37,10 +37,34 @@ void * receivingThreadHandler(void * threadArguments)
|
|||
while (true)
|
||||
{
|
||||
gnutls_record_recv(session, ¤tMessage, sizeof(struct ServerToClientMessage));
|
||||
wattrset(chatWindow, A_BOLD);
|
||||
wprintw(chatWindow, "<%s>: ", currentMessage.name);
|
||||
wattrset(chatWindow, A_NORMAL);
|
||||
wprintw(chatWindow, "%s\n", currentMessage.content);
|
||||
|
||||
switch (currentMessage.type)
|
||||
{
|
||||
case SYSTEM:
|
||||
{
|
||||
wattrset(gameWindow, A_BOLD);
|
||||
wprintw(gameWindow, "%s\n", currentMessage.content);
|
||||
wattrset(gameWindow, A_NORMAL);
|
||||
break;
|
||||
}
|
||||
case LOCAL_CHAT:
|
||||
{
|
||||
wattrset(chatWindow, A_BOLD);
|
||||
wprintw(chatWindow, "<%s>: ", currentMessage.name);
|
||||
wattrset(chatWindow, A_NORMAL);
|
||||
wprintw(chatWindow, "%s\n", currentMessage.content);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
wattrset(chatWindow, A_BOLD);
|
||||
wprintw(chatWindow, "<%s>: ", currentMessage.name);
|
||||
wattrset(chatWindow, A_NORMAL);
|
||||
wprintw(chatWindow, "%s\n", currentMessage.content);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
redrawClientLayout(gameWindow, chatWindow, inputWindow);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -167,6 +167,14 @@ int main (int argc, char ** argv)
|
|||
sprintf(newConnection->player->name, "Player %02d", globalPlayerList->count + 1);
|
||||
addToPlayerList(newConnection->player, globalPlayerList);
|
||||
|
||||
// Send a welcome message:
|
||||
struct ServerToClientMessage welcomeMessage;
|
||||
welcomeMessage.type = SYSTEM;
|
||||
sprintf(welcomeMessage.content, (clientConnections.clientCount > 1) ?
|
||||
"Welcome to the server. There are %d players connected." : "Welcome to the server. There is %d player connected.",
|
||||
clientConnections.clientCount);
|
||||
|
||||
gnutls_record_send(*tlsSession, &welcomeMessage, sizeof(struct ServerToClientMessage));
|
||||
|
||||
// Print a message:
|
||||
printf("New connection established. %d client(s), session ID %u.\n",
|
||||
|
|
Loading…
Reference in New Issue