tMessage *Message_AppendF(tServer *Server, int Type, const char *Source, const char *Dest, const char *Message, ...);\r
tMessage *Message_Append(tServer *Server, int Type, const char *Source, const char *Dest, const char *Message);\r
tWindow *Window_Create(tServer *Server, const char *Name);\r
+void Redraw_Screen(void);\r
\r
int ProcessIncoming(tServer *Server);\r
// --- Helpers\r
\r
// HACK: Static server entry\r
// UCC (University [of Western Australia] Computer Club) IRC Server\r
- //gWindow_Status.Server = Server_Connect( "UCC", "130.95.13.18", 6667 );\r
- gWindow_Status.Server = Server_Connect( "UCC", "10.0.2.2", 6667 );\r
+ gWindow_Status.Server = Server_Connect( "UCC", "130.95.13.18", 6667 );\r
+// gWindow_Status.Server = Server_Connect( "Host", "10.0.2.2", 6667 );\r
+// gWindow_Status.Server = Server_Connect( "BitlBee", "192.168.1.34", 6667 );\r
\r
if( !gWindow_Status.Server )\r
return -1;\r
for( win = gpWindows; win && window_num--; win = win->Next );\r
if( win ) {\r
gpCurrentWindow = win;\r
+ Redraw_Screen();\r
}\r
// Otherwise, silently ignore\r
}\r
return ret;\r
}\r
\r
+void Redraw_Screen(void)\r
+{\r
+ int y = 0;\r
+ tMessage *msg;\r
+\r
+ printf("\x1B[2J"); // Clear screen\r
+ printf("\x1B[0;0H"); // Reset cursor\r
+\r
+ msg = gpCurrentWindow->Messages;\r
+ \r
+ // TODO: Title bar?\r
+\r
+ // Note: This renders from the bottom up\r
+ for( y = giTerminal_Height - 1; y -- && msg; msg = msg->Next)\r
+ {\r
+ int msglen = strlen(msg->Data);\r
+ int prefix_len = 3 + strlen(msg->Source);\r
+ int line_avail = giTerminal_Width - prefix_len;\r
+ int i = 0, done = 0;\r
+ \r
+ y -= msglen / line_avail; // Extra lines (y-- above handles the 1 line case)\r
+ SetCursorPos(y, 0);\r
+ printf("[%s] ", msg->Source);\r
+ \r
+ while(done < msglen) {\r
+ done += printf("%.*s", line_avail, msg->Data+done);\r
+ SetCursorPos(y+i, prefix_len);\r
+ i ++;\r
+ }\r
+ }\r
+\r
+ // Bottom line is rendered by the prompt\r
+}\r
+\r
void Cmd_PRIVMSG(tServer *Server, const char *Dest, const char *Src, const char *Message)\r
{\r
Message_Append(Server, MSG_TYPE_STANDARD, Dest, Src, Message);\r
int pos = 0;\r
char *ident, *cmd;\r
\r
+ \r
// Message?\r
if( *Line == ':' )\r
{\r
\r
switch(num)\r
{\r
+ case 353: // /NAMES list\r
+ // <user> = <channel> :list\r
+ GetValue(Line, &pos); // '='\r
+ user = GetValue(Line, &pos); // Actually channel\r
+ message = Line + pos + 1; // List\r
+ Message_Append(Server, MSG_TYPE_SERVER, user, "", message);\r
+ break;\r
+ case 366: // end of /NAMES list\r
+// Message_Append()\r
+ break;\r
+ case 372: // MOTD Data\r
+ case 376: // MOTD End\r
+ \r
default:\r
//printf("[%s] %i %s\n", Server->Name, num, message);\r
Message_Append(Server, MSG_TYPE_SERVER, ident, user, message);\r
else {\r
\r
// Command to client\r
- printf("Client Command: %s", Line);\r
+ Message_AppendF(NULL, MSG_TYPE_UNK, "", "", "Client Command: %s", Line);\r
}\r
}\r
\r
return -1;\r
}\r
\r
- printf("iface = '%s'\n", iface);\r
+// printf("iface = '%s'\n", iface);\r
\r
// Open client socket\r
// TODO: Move this out to libnet?\r
}\r
\r
// Set remote port and address\r
- printf("Setting port and remote address\n");\r
+// printf("Setting port and remote address\n");\r
ioctl(fd, 5, &PortNumber);\r
ioctl(fd, 6, addrBuffer);\r
\r
// Connect\r
- printf("Initiating connection\n");\r
+// printf("Initiating connection\n");\r
if( ioctl(fd, 7, NULL) == 0 ) {\r
// Shouldn't happen :(\r
fprintf(stderr, "Unable to start connection\n");\r
\r
int SetCursorPos(int Row, int Col)\r
{\r
+ int rv;\r
if( Row == -1 ) {\r
Row = Col / giTerminal_Width;\r
Col = Col % giTerminal_Width;\r
}\r
+ rv = ioctl(1, 9, NULL); // Ugh, constants\r
printf("\x1B[%i;%iH", Col, Row);\r
- return ioctl(1, 9, NULL); // Ugh, constants\r
+ return rv;\r
}\r
\r
static inline int isdigit(int ch)\r