예제 #1
0
 public static int WallUser(int id, int targetid, string msg)
 {
     if (targetid != -1)
     {
         TCPServer.SendToId(targetid, "WALL" + TCPServer.sep1 + id.ToString() + TCPServer.sep2 + msg);
         return(0);
     }
     else
     {
         return(-1);
     }
 }
예제 #2
0
 public static int MessageUser(int id, int targetid, string msg)
 {
     if (targetid != -1)
     {
         TCPServer.SendToId(targetid, "MESSAGE" + TCPServer.sep1 + id.ToString() + TCPServer.sep2 + msg);
         TCPServer.SendToId(id, "MESSAGESENT" + TCPServer.sep1);
         return(0);
     }
     else
     {
         return(-1);
     }
 }
        static public void processcommand(int id, string cmd)
        {
            string[] pieces;

            if (cmd.IndexOf(TCPServer.sep1) >= 1)
            {
                try
                {
                    string part1 = cmd.left(cmd.IndexOf(TCPServer.sep1));
                    string part2 = cmd.right(cmd.Length - (cmd.IndexOf(TCPServer.sep1) + 1));

                    switch (part1)
                    {
                    case "NEWUSER":
                        UserControl.ConnectUser(id);
                        TCPServer.SendToId(id, "CONNECTED" + TCPServer.sep1 + id);
                        break;

                    case "USERNAME":
                        if (UserControl.HandletoId(part2) == -1)
                        {
                            TCPServer.users[id].name = part2;
                            TCPServer.SendToId(id, "USERNAME Set to " + TCPServer.users[id].name);
                        }
                        else
                        {
                            TCPServer.SendToId(id, "ERROR" + TCPServer.sep1 + "User already online");
                        }
                        break;

                    case "SENDMSG":
                        pieces = part2.Split(TCPServer.sep2);
                        if (UserControl.MessageUser(id, Convert.ToInt32(pieces[0]), pieces[1]) != 0)
                        {
                            TCPServer.SendToId(id, "ERROR" + TCPServer.sep1 + "Message failed, user not online");
                        }
                        break;

                    case "SENDALL":
                        UserControl.MessageAll(id, part2);
                        break;

                    case "WALL":
                        pieces = part2.Split(TCPServer.sep2);
                        if (UserControl.MessageUser(id, Convert.ToInt32(pieces[0]), pieces[1]) != 0)
                        {
                            TCPServer.SendToId(id, "ERROR" + TCPServer.sep1 + "Wall failed, user not online");
                        }
                        break;

                    case "WALLALL":
                        UserControl.MessageAll(id, part2);
                        break;

                    case "HANDLETOID":
                        TCPServer.SendToId(id, "HANDLETOID:" + UserControl.HandletoId(part2));
                        break;

                    case "LOGOFF":
                        UserControl.DisconnectUser(id);
                        Logger.Log("Connection: " + id + " disconnected (clean)");
                        break;

                    case "ECHO":
                        TCPServer.SendToId(id, "ECHO" + TCPServer.sep1 + id);
                        break;

                    case "SHUTDOWN":
                        TCPServer.ServerRunning = false;
                        Logger.Log("Starting Server Shutdown...");
                        TCPServer.server.Stop();
                        //TCPServer.se
                        break;

                    case "LOG":
                        Logger.Log(part2 + " (" + id + ")");
                        break;

                    default:
                        //logerror(id,1,"Command not matched - " + cmd);
                        break;
                    }
                }
                catch
                {
                    //logerror(id,3,"Generic error with MainHandler - " + cmd);
                }
            }
            else
            {
                //logerror(id,2,"Command not formatted correctly - " + cmd);
            }
        }