Exemplo n.º 1
0
        /*============================================================================================
         * Process any commands sent by someone
         *
         *============================================================================================*/
        public string MsgProc(string msg, string thGUID)
        {
            int ui = usersList.FindIndex(x => x.ThreadGUID.Equals(thGUID));
            int ct = clientThreads.FindIndex(x => x.ThreadGUID.Equals(thGUID));

            ClassCommandInfo cmdInfo = new ClassCommandInfo(ui, usersList[ui]);

            if (mw.debugLevel > 4)
            {
                mw.Display(usersList[ui].NickName + ": " + msg);
            }

            // Is there a message to process?
            if (msg.Length > 1)
            {
                usersList[ui].msgCount++;
                usersList[ui].lastMsgDT = DateTime.Now;

                // Does the message start with a forward slash?
                if (msg.Substring(0, 1).Equals("/") && ui >= 0)
                {
                    // Process the command
                    msg            += " ";
                    cmdInfo.command = msg.Substring(1, msg.IndexOf(' ') - 1).Trim().ToUpper();
                    cmdInfo.msg     = msg.Substring(msg.IndexOf(' ')).Trim();

                    //Console.WriteLine("Processing command " + command);
                    if (cmdInfo.ThisUser.RegisteredGUID.Length > 0)
                    {
                        // Room commands for registered users
                        if (cmdInfo.command.Length > 0)
                        {
                            RoomCommands.Process(ref cmdInfo);
                        }
                    }

                    // Commands for Everyone
                    if (cmdInfo.command.Length > 0)
                    {
                        UserCommands.Process(ref cmdInfo);
                    }

                    // unregistered or not yet logged in
                    if (cmdInfo.command.Length > 0)
                    {
                        RegistrationCommands.Process(ref cmdInfo);
                    }

                    // get any changes made to the user while in the command processors
                    if (cmdInfo.ThisUser.WasChanged)
                    {
                        // This is catch up... if any registration related changes were made by the
                        // commands then they should already be saved in the registration file
                        if (mw.debugLevel > 8)
                        {
                            mw.Display(">>> Updating user list");
                        }

                        // Properties that are passed between the registration module
                        if (cmdInfo.ThisUser.Dif("RegisteredGUID"))
                        {
                            // when this is updated, other fields that are not normally
                            // tracked must be updated also because we've just loaded
                            // the values from the registration table
                            usersList[ui].RegisteredGUID = cmdInfo.ThisUser.RegisteredGUID;
                            usersList[ui].lastOnDT       = cmdInfo.ThisUser.lastOnDT;
                            usersList[ui].registeredDT   = cmdInfo.ThisUser.registeredDT;
                        }

                        if (cmdInfo.ThisUser.Dif("Email"))
                        {
                            usersList[ui].Email = cmdInfo.ThisUser.Email;
                        }
                        if (cmdInfo.ThisUser.Dif("FullName"))
                        {
                            usersList[ui].FullName = cmdInfo.ThisUser.FullName;
                        }

                        if (cmdInfo.ThisUser.Dif("NickName"))
                        {
                            usersList[ui].NickName = cmdInfo.ThisUser.NickName;
                            if (ct >= 0)
                            {
                                clientThreads[ct].nickName = cmdInfo.ThisUser.NickName;
                            }
                            else
                            {
                                mw.Display("MsgProc failed to match ClientThreads with ID " + thGUID);
                            }
                        }

                        if (cmdInfo.ThisUser.Dif("Status"))
                        {
                            usersList[ui].Status = cmdInfo.ThisUser.Status;
                        }
                        if (cmdInfo.ThisUser.Dif("UserName"))
                        {
                            usersList[ui].UserName = cmdInfo.ThisUser.UserName;
                        }
                        if (cmdInfo.ThisUser.Dif("UserRights"))
                        {
                            usersList[ui].UserRights = cmdInfo.ThisUser.UserRights;
                        }

                        // session properties managed by the Rooms module
                        if (cmdInfo.ThisUser.Dif("AwayMsg"))
                        {
                            usersList[ui].AwayMsg = cmdInfo.ThisUser.AwayMsg;
                        }
                        if (cmdInfo.ThisUser.Dif("IgnoreList"))
                        {
                            usersList[ui].IgnoreList = cmdInfo.ThisUser.IgnoreList;
                        }
                        if (cmdInfo.ThisUser.Dif("Seating"))
                        {
                            usersList[ui].Seating = cmdInfo.ThisUser.Seating;
                        }
                        if (cmdInfo.ThisUser.Dif("CurrentRoom"))
                        {
                            usersList[ui].CurrentRoom = cmdInfo.ThisUser.CurrentRoom;
                        }
                    }

                    // If the command property still has a length then it did
                    // not get executed ans was either mispelled or invalid
                    if (cmdInfo.command.Length > 0)
                    {
                        cmdInfo.msgOut = string.Format("Command '{0}' is not a valid command for you at this time.\r\nUse /HELP for more information.\r\n", cmdInfo.command);
                    }
                }
                else
                {
                    if (usersList[ui].AwayMsg != null && usersList[ui].AwayMsg.Length > 0)
                    {
                        // an away msg means you're away
                        cmdInfo.msgOut = "You have an away message set, so no one will hear you.";
                    }
                    else
                    {
                        // normal message
                        cmdInfo.Results = usersList[ui].NickName + ": " + msg;
                    }
                }
            }

            // Was there something to send back to the client?
            if (cmdInfo.msgOut.Length > 0)
            {
                SendToGUID(cmdInfo.ThisUser.ThreadGUID, cmdInfo.msgOut);
            }

            return(cmdInfo.Results);
        }