Exemplo n.º 1
0
            /// <summary>
            /// Called when a packet is received, the packet will be processed and the connection will be closed (after processing packet) in all cases. No errors will be thrown.
            /// </summary>
            /// <param name="iAr"></param>
            private void dataArrival(IAsyncResult iAr)
            {
                try
                {
                    int    bytesReceived = Connector.EndReceive(iAr);
                    string Data          = System.Text.Encoding.ASCII.GetString(dataBuffer, 0, bytesReceived);

                    string   musHeader = Data.Substring(0, 4);
                    string[] musData   = Data.Substring(4).Split(Convert.ToChar(2));
                    Out.WriteLine("DATA: " + Data);
                    #region MUS trigger commands
                    // Unsafe code, but on any error it jumps to the catch block & disconnects the socket
                    switch (musHeader)
                    {
                    case "HKTM":     // Housekeeping - textmessage [BK] :: "HKTM123This is a test message to user with ID 123"
                    {
                        int    userID  = int.Parse(musData[0]);
                        string Message = musData[1];
                        if (userManager.containsUser(userID))
                        {
                            userManager.getUser(userID).sendData("BK" + Message);
                        }
                        break;
                    }

                    case "HKMW":     // Housekeeping - alert user [mod warn] :: "HKMW123This is a test mod warn to user with ID 123"
                    {
                        int    userID  = int.Parse(musData[0]);
                        string Message = musData[1];
                        if (userManager.containsUser(userID))
                        {
                            userManager.getUser(userID).sendData("B!" + Message + Convert.ToChar(2));
                        }
                        break;
                    }

                    case "HKUK":     // Housekeeping - kick user from room [mod warn] :: "HKUK123This is a test kick from room + modwarn for user with ID 123"
                    {
                        int         userID  = int.Parse(musData[0]);
                        string      Message = musData[1];
                        virtualUser User    = userManager.getUser(userID);
                        if (User.Room != null)
                        {
                            User.Room.removeUser(User.roomUser.roomUID, true, Message);
                        }
                        break;
                    }

                    case "HKAR":     // Housekeeping - alert certain rank with BK message, contains flag to include users with higher rank :: "HKAR11This is a test message for all users with rank 1 and higher, so kindof a Hotel alert :D"
                    {
                        byte   Rank          = byte.Parse(musData[0]);
                        bool   includeHigher = (musData[1] == "1");
                        string Message       = musData[2];
                        userManager.sendToRank(Rank, includeHigher, "BK" + Message);
                        break;
                    }

                    case "HKSB":     // Housekeeping - ban user & kick from room :: "HKSB123This is a test ban for user with ID 123"
                    {
                        int         userID  = int.Parse(musData[0]);
                        string      Message = musData[1];
                        virtualUser User    = userManager.getUser(userID);
                        User.sendData("@c" + Message);
                        User.Disconnect(1000);
                        break;
                    }

                    case "HKRC":     // Housekeeping - rehash catalogue :: "HKRC"
                    {
                        catalogueManager.Init(false);
                        break;
                    }

                    case "UPRA":     // User profile - reload figure, sex and mission (poof!)
                    {
                        int userID = int.Parse(musData[0]);
                        if (userManager.containsUser(userID))
                        {
                            userManager.getUser(userID).refreshAppearance(true, true, true);
                        }
                        break;
                    }

                    case "UPRC":         // User profile - reload credits
                    {
                        int userID = int.Parse(musData[0]);
                        userManager.getUser(userID).refreshValueables(true, false);
                        break;
                    }

                    case "UPRT":     // User profile - reload tickets
                    {
                        int userID = int.Parse(musData[0]);
                        if (userManager.containsUser(userID))
                        {
                            userManager.getUser(userID).refreshValueables(false, true);
                        }
                        break;
                    }

                    case "UPRS":     // User profile - reload subscription (and badges)
                    {
                        int userID = int.Parse(musData[0]);
                        if (userManager.containsUser(userID))
                        {
                            virtualUser User = userManager.getUser(userID);
                            User.refreshClub();
                            User.refreshBadges();
                        }
                        break;
                    }

                    case "UPRH":    // User profile - reload hand
                    {
                        int userID = int.Parse(musData[0]);
                        if (userManager.containsUser(userID))
                        {
                            userManager.getUser(userID).refreshHand("new");
                        }
                        break;
                    }
                    }
                    #endregion
                }
                catch { }
                finally { killConnection(); }
            }