int ParseUserCommand(char *String);\r
// --- \r
tServer *Server_Connect(const char *Name, const char *AddressString, short PortNumber);\r
+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
\r
void ExitHandler(void)\r
{\r
printf("\x1B[?1047l");\r
+ printf("Quit\n");\r
}\r
\r
int main(int argc, const char *argv[], const char *envp[])\r
printf("\x1B[?1047h");\r
printf("\x1B[%i;%ir", 0, giTerminal_Height-1);\r
\r
+ SetCursorPos(giTerminal_Height-1, 0);\r
+ printf("[(status)] ");\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
if( !gWindow_Status.Server )\r
return -1;\r
\r
- readline_info = Readline_Init(1);\r
- \r
SetCursorPos(giTerminal_Height-1, 0);\r
printf("[(status)] ");\r
+ readline_info = Readline_Init(1);\r
\r
for( ;; )\r
{\r
free(cmd);\r
// Prompt\r
SetCursorPos(giTerminal_Height-1, 0);\r
+ printf("\x1B[K"); // Clear line\r
if( gpCurrentWindow->Name[0] )\r
printf("[%s:%s] ", gpCurrentWindow->Server->Name, gpCurrentWindow->Name);\r
else\r
}\r
else if( strcmp(command, "/quit") == 0 )\r
{\r
- char *quit_message = GetValue(String, &pos);\r
+ char *quit_message = String + pos;\r
tServer *srv;\r
\r
if( quit_message == NULL || quit_message[0] == '\0' )\r
window_num = 1;\r
for( win = gpWindows; win; win = win->Next, window_num ++ )\r
{\r
- char tmp[snprintf(NULL, 1000, "%i: %s/%s", window_num, win->Server->Name, win->Name)+1];\r
- snprintf(tmp, 1000, "%i: %s/%s", window_num, win->Server->Name, win->Name);\r
- Message_Append(NULL, MSG_TYPE_SERVER, "client", "", tmp);\r
+ if( win->Name[0] ) {\r
+ Message_AppendF(NULL, MSG_TYPE_SERVER, "client", "",\r
+ "%i: %s/%s", window_num, win->Server->Name, win->Name);\r
+ }\r
+ else {\r
+ Message_AppendF(NULL, MSG_TYPE_SERVER, "client", "",\r
+ "%i: (status)", window_num);\r
+ }\r
}\r
}\r
}\r
else\r
{\r
- int len = snprintf(NULL, 0, "Unknown command %s", command);\r
- char buf[len+1];\r
- snprintf(buf, len+1, "Unknown command %s", command);\r
- Message_Append(NULL, MSG_TYPE_SERVER, "client", "", buf);\r
+ Message_AppendF(NULL, MSG_TYPE_SERVER, "client", "", "Unknown command %s", command);\r
}\r
}\r
else\r
// - Only send if server is valid and window name is non-empty\r
if( gpCurrentWindow->Server && gpCurrentWindow->Name[0] )\r
{\r
+ Message_Append(gpCurrentWindow->Server, MSG_TYPE_STANDARD,\r
+ gsNickname, gpCurrentWindow->Name, String);\r
writef(gpCurrentWindow->Server->FD,\r
"PRIVMSG %s :%s\n", gpCurrentWindow->Name,\r
String\r
gpServers = ret;\r
\r
// Read some initial data\r
- printf("%s: Connection opened\n", Name);\r
+ Message_Append(NULL, MSG_TYPE_SERVER, Name, "", "Connection opened");\r
ProcessIncoming(ret);\r
\r
// Identify\r
writef(ret->FD, "USER %s %s %s : %s\n", gsUsername, gsHostname, AddressString, gsRealName);\r
writef(ret->FD, "NICK %s\n", gsNickname);\r
- printf("%s: Identified\n", Name);\r
+ Message_Append(NULL, MSG_TYPE_SERVER, Name, "", "Identified");\r
+ //printf("%s: Identified\n", Name);\r
\r
return ret;\r
}\r
\r
+tMessage *Message_AppendF(tServer *Server, int Type, const char *Source, const char *Dest, const char *Message, ...)\r
+{\r
+ va_list args;\r
+ int len;\r
+ va_start(args, Message);\r
+ len = vsnprintf(NULL, 1000, Message, args);\r
+ {\r
+ char buf[len+1];\r
+ vsnprintf(buf, len+1, Message, args);\r
+ return Message_Append(Server, Type, Source, Dest, buf);\r
+ }\r
+}\r
+\r
tMessage *Message_Append(tServer *Server, int Type, const char *Source, const char *Dest, const char *Message)\r
{\r
tMessage *ret;\r
int msgLen = strlen(Message);\r
\r
// NULL servers are internal messages\r
- if( Server == NULL )\r
+ if( Server == NULL || Source[0] == '\0' )\r
{\r
win = &gWindow_Status;\r
}\r
\r
{\r
int pos = SetCursorPos(giTerminal_Height-2, 0);\r
- printf("\x1B[T"); // Scroll down 1 (free space below)\r
#if 1\r
if( win == gpCurrentWindow ) {\r
+ printf("\x1B[T"); // Scroll down 1 (free space below)\r
printf("[%s] %s\n", Source, Message);\r
}\r
#else\r
}\r
else\r
{\r
- printf("Unknown message %s (%s)\n", cmd, Line+pos);\r
+ Message_AppendF(Server, MSG_TYPE_SERVER, "", "", "Unknown message %s (%s)\n", cmd, Line+pos);\r
}\r
}\r
else {\r