Usermode/irc - Fixes
authorJohn Hodge <[email protected]>
Thu, 4 Aug 2011 00:16:59 +0000 (08:16 +0800)
committerJohn Hodge <[email protected]>
Thu, 4 Aug 2011 00:16:59 +0000 (08:16 +0800)
- Added full screen redraw on window change
- Fixed SetCursorPosision to get the _old_ position, not new

Usermode/Applications/irc_src/main.c

index b59a91e..aa0f2d4 100644 (file)
@@ -62,6 +62,7 @@ tServer       *Server_Connect(const char *Name, const char *AddressString, short PortN
 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
 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
  int   ProcessIncoming(tServer *Server);\r
 // --- Helpers\r
@@ -114,8 +115,9 @@ int main(int argc, const char *argv[], const char *envp[])
        \r
        // HACK: Static server entry\r
        // UCC (University [of Western Australia] Computer Club) IRC Server\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
        \r
        if( !gWindow_Status.Server )\r
                return -1;\r
@@ -250,6 +252,7 @@ int ParseUserCommand(char *String)
                                for( win = gpWindows; win && window_num--; win = win->Next );\r
                                if( win ) {\r
                                        gpCurrentWindow = win;\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
                                }\r
                                // Otherwise, silently ignore\r
                        }\r
@@ -468,6 +471,40 @@ tWindow *Window_Create(tServer *Server, const char *Name)
        return ret;\r
 }\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
 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
@@ -481,6 +518,7 @@ void ParseServerLine(tServer *Server, char *Line)
         int    pos = 0;\r
        char    *ident, *cmd;\r
        \r
         int    pos = 0;\r
        char    *ident, *cmd;\r
        \r
+       \r
        // Message?\r
        if( *Line == ':' )\r
        {\r
        // Message?\r
        if( *Line == ':' )\r
        {\r
@@ -507,6 +545,19 @@ void ParseServerLine(tServer *Server, char *Line)
                        \r
                        switch(num)\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
                        default:\r
                                //printf("[%s] %i %s\n", Server->Name, num, message);\r
                                Message_Append(Server, MSG_TYPE_SERVER, ident, user, message);\r
@@ -557,7 +608,7 @@ void ParseServerLine(tServer *Server, char *Line)
        else {\r
                \r
                // Command to client\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
        }\r
 }\r
 \r
@@ -659,7 +710,7 @@ int OpenTCP(const char *AddressString, short PortNumber)
                return -1;\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
        // Open client socket\r
        // TODO: Move this out to libnet?\r
@@ -678,12 +729,12 @@ int OpenTCP(const char *AddressString, short PortNumber)
        }\r
        \r
        // Set remote port and address\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
        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
        if( ioctl(fd, 7, NULL) == 0 ) {\r
                // Shouldn't happen :(\r
                fprintf(stderr, "Unable to start connection\n");\r
@@ -724,12 +775,14 @@ char *GetValue(char *Src, int *Ofs)
 \r
 int SetCursorPos(int Row, int Col)\r
 {\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
        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
        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
 }\r
 \r
 static inline int isdigit(int ch)\r

UCC git Repository :: git.ucc.asn.au