Initial ncurses setup, and layout of client.
This commit is contained in:
parent
c043da64a2
commit
50dcddfc56
|
@ -1,7 +1,7 @@
|
|||
bin_PROGRAMS = SilverMUDServer SilverMUDClient
|
||||
dist_doc_DATA = README.org
|
||||
SilverMUDServer_CFLAGS = -I/usr/include/guile/3.0 -I/usr -lguile-3.0 -lgc -lpthread -ldl -lgnutls -g
|
||||
SilverMUDClient_CFLAGS = -I/usr/include/guile/3.0 -I/usr -lguile-3.0 -lgc -lpthread -ldl -lgnutls -g
|
||||
SilverMUDClient_CFLAGS = -I/usr/include/guile/3.0 -I/usr -lguile-3.0 -lgc -lpthread -ldl -lgnutls -g -lncurses
|
||||
|
||||
SilverMUDServer_SOURCES = \
|
||||
source/messages.c \
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
#include <sys/socket.h>
|
||||
#include <gnutls/gnutls.h>
|
||||
|
||||
#include "../config.h"
|
||||
#include "../messages.h"
|
||||
|
||||
int main (int argc, char ** argv)
|
||||
|
@ -65,12 +66,77 @@ int main (int argc, char ** argv)
|
|||
}
|
||||
while (returnValue < 0 && gnutls_error_is_fatal(returnValue) == 0);
|
||||
|
||||
|
||||
struct ClientToServerMessage message;
|
||||
while (true)
|
||||
// Initialize ncurses:
|
||||
initscr();
|
||||
keypad(stdscr, TRUE);
|
||||
|
||||
if (!has_colors())
|
||||
{
|
||||
fgets(message.content, 1024, stdin);
|
||||
gnutls_record_send(tlsSession, &message, 1024);
|
||||
endwin();
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
// Enable colours:
|
||||
start_color();
|
||||
use_default_colors();
|
||||
init_pair(1, COLOR_GREEN, -1);
|
||||
|
||||
// Variables needed for the main loop:
|
||||
int height, width;
|
||||
getmaxyx(stdscr, height, width);
|
||||
struct ClientToServerMessage message;
|
||||
|
||||
WINDOW * chatWindow, * gameWindow;
|
||||
gameWindow = newwin((height / 2) - 1, width - 2, 1, 1);
|
||||
chatWindow = newwin((height / 2) - 3, width - 2, (height / 2) + 1, 1);
|
||||
|
||||
scrollok(gameWindow, TRUE);
|
||||
scrollok(chatWindow, TRUE);
|
||||
|
||||
while (true)
|
||||
{
|
||||
// Store the current size of the terminal:
|
||||
getmaxyx(stdscr, height, width);
|
||||
|
||||
|
||||
// Draw the lines that will seperate windows:
|
||||
wborder(stdscr, ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ');
|
||||
mvwhline(stdscr, 0, 0, '=', width);
|
||||
mvwhline(stdscr, height / 2, 0, '=', width);
|
||||
mvwhline(stdscr, height - 2, 0, '=', width);
|
||||
|
||||
// Write the labels for windows:
|
||||
attron(COLOR_PAIR(1));
|
||||
mvwprintw(stdscr, 0, 1, " SilverMUD | Version %s ", PACKAGE_VERSION);
|
||||
mvwprintw(stdscr, height / 2, 1, " Chat ");
|
||||
mvwprintw(stdscr, height - 2, 1, " Input ");
|
||||
attroff(COLOR_PAIR(1));
|
||||
|
||||
wrefresh(stdscr);
|
||||
|
||||
// Move the windows into place:
|
||||
mvwin(gameWindow, 1, 1);
|
||||
mvwin(chatWindow, (height / 2) + 1 , 1);
|
||||
wresize(gameWindow, (height / 2) - 1, width - 2);
|
||||
wresize(chatWindow, ((height / 2) - 2) - (1 - (height % 2)), width - 2);
|
||||
|
||||
wrefresh(gameWindow);
|
||||
wrefresh(chatWindow);
|
||||
|
||||
// Move to the input area:
|
||||
wmove(stdscr, height - 1, 1);
|
||||
wgetnstr(stdscr, message.content, 1024);
|
||||
|
||||
// Clear the input area:
|
||||
wmove(stdscr, height - 2, 1);
|
||||
clrtoeol();
|
||||
|
||||
if (message.content[0] != '\0')
|
||||
{
|
||||
wprintw(gameWindow, "%s\n", message.content);
|
||||
wprintw(chatWindow, "%s\n", message.content);
|
||||
gnutls_record_send(tlsSession, &message, 1024);
|
||||
}
|
||||
}
|
||||
|
||||
// Return a successful status code to the operating system:
|
||||
|
|
|
@ -162,7 +162,8 @@ int main (int argc, char ** argv)
|
|||
addNewConnection(&clientConnections, newSocket, tlsSession);
|
||||
|
||||
// Print a message:
|
||||
printf("New connection established! %d clients, session ID %u.\n", clientConnections.clientCount, tlsSession);
|
||||
printf("New connection established. %d client(s), session ID %u.\n",
|
||||
clientConnections.clientCount, tlsSession);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -174,7 +175,7 @@ int main (int argc, char ** argv)
|
|||
int returnValue = gnutls_record_recv(*connection->tlsSession, &message, sizeof(struct ClientToServerMessage));
|
||||
if (returnValue == 0 || returnValue == -10)
|
||||
{
|
||||
printf("Closing session ID: %d\n", *connection->tlsSession);
|
||||
printf("Closing session ID: %u.\n", *connection->tlsSession);
|
||||
epoll_ctl(connectedClients, EPOLL_CTL_DEL, connection->fileDescriptor, &watchedEvents);
|
||||
gnutls_bye(*connection->tlsSession, 2);
|
||||
shutdown(connection->fileDescriptor, 2);
|
||||
|
@ -183,7 +184,7 @@ int main (int argc, char ** argv)
|
|||
}
|
||||
else if (returnValue == sizeof(struct ClientToServerMessage))
|
||||
{
|
||||
printf("%s", message.content);
|
||||
printf("%s\n", message.content);
|
||||
fflush(stdout);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue