Esempio n. 1
0
        public override void Handle(ReBornWarRock_PServer.GameServer.Virtual_Objects.User.virtualUser User)
        {
            try
            {
                int ChatType = Convert.ToInt32(getBlock(0));
                int TargetID = Convert.ToInt32(getBlock(1));

                string TargetName = getBlock(2);
                string exMessage  = getBlock(3);
                string Message    = WordManager.GetBadWord(exMessage);

                string sMessage = Message.Split(new string[] { ">>" + Convert.ToChar(0x1D).ToString() }, StringSplitOptions.None)[1].Replace(Convert.ToChar(0x1D), Convert.ToChar(0x20));
                if (User.isCommand(sMessage))
                {
                    return;
                }

                int  MuteTime      = 60;
                long ChatTimeCheck = Structure.currTimeStamp;
                if (User.isMuted == true && User.MutedTime > ChatTimeCheck)
                {
                    User.send(new PACKET_CHAT("SERVER", PACKET_CHAT.ChatType.Whisper, "SERVER >> You are muted, please try it later again!", User.SessionID, User.Nickname));
                    return;
                }
                else
                {
                    User.isMuted = false; User.MutedTime = 0;
                }
                DB.runQuery("INSERT INTO chatlogs (`userid`, `roomid`, `message`, `timestamp`) VALUES ('" + User.UserID + "', '" + ((User.Room == null) ? -1 : User.Room.ID) + "', '" + DB.Stripslash(sMessage) + "', '" + Structure.currTimeStamp + "')");
                if (User.LastChatTick == 0)
                {
                    User.LastChatTick = Environment.TickCount;
                }

                long ChatTime = Environment.TickCount - User.LastChatTick;

                if (ChatTime != 0 && ChatTime < 1000)
                {
                    User.ChatWarnings++;
                    if (User.ChatWarnings >= 5 && User.Rank < 3)
                    {
                        User.MutedTime = Structure.currTimeStamp + MuteTime;
                        User.send(new PACKET_CHAT("SERVER", PACKET_CHAT.ChatType.Whisper, "SERVER >> You have been muted!", User.SessionID, User.Nickname));
                        User.isMuted = true;
                        return;
                    }
                }

                User.LastChatTick = Environment.TickCount;

                switch (ChatType)
                {
                case 2:
                {
                    ReBornWarRock_PServer.GameServer.Virtual_Objects.User.virtualUser Target = UserManager.getUser(TargetName);
                    if (Target is ReBornWarRock_PServer.GameServer.Virtual_Objects.User.virtualUser && Target.SessionID > 0)
                    {
                        User.send(new PACKET_CHAT(User, PACKET_CHAT.ChatType.Whisper, Message, Target.SessionID, Target.Nickname));
                        if (!User.Equals(Target))
                        {
                            Target.send(new PACKET_CHAT(User, PACKET_CHAT.ChatType.Whisper, Message, Target.SessionID, Target.Nickname));
                        }
                    }
                    else
                    {
                        User.send(new PACKET_CHAT(PACKET_CHAT.ErrorCodes.ErrorUser, TargetName + Convert.ToChar(0x1D)));
                    }
                    break;
                }

                case 3:     // Lobby2Channel
                {
                    if (User.ColorChat == System.Drawing.Color.Empty || User.Rank < 2)
                    {
                        if (User.Rank > 2)
                        {
                            TargetID = 999;
                        }
                        UserManager.sendToChannel(User.Channel, false, new PACKET_CHAT(User, PACKET_CHAT.ChatType.Lobby_ToChannel, Message, (User.Rank > 4) ? 999 : TargetID, TargetName));
                    }
                    else
                    {
                        UserManager.sendToChannel(User.Channel, false, new PACKET_CHAT_COLOR(Message, PACKET_CHAT_COLOR.ChatType.Normal, User.ColorChat));
                        //UserManager.sendToChannel(usr.channel, false, new SP_ColoredChat(message, SP_ColoredChat.ChatType.Normal, usr.chatColor));
                    }
                    break;
                }

                case 4:     // Room2All
                {
                    if (User.Room != null)
                    {
                        if (User.ColorChat != System.Drawing.Color.Empty && !User.Room.GameActive && User.Rank >= 2)
                        {
                            User.Room.send(new PACKET_CHAT_COLOR(Message, PACKET_CHAT_COLOR.ChatType.Normal, User.ColorChat));
                        }
                        else
                        {
                            if (User.hasItem("CC02") && User.Room.RoomStatus == 1 && User.RoomSlot == User.Room.RoomMasterSlot && User.Rank < 3)
                            {
                                TargetID = 998;
                            }
                            else if (User.Rank > 2)
                            {
                                TargetID = 999;
                            }

                            User.Room.send(new PACKET_CHAT(User, PACKET_CHAT.ChatType.Room_ToAll, Message, TargetID, TargetName));
                        }
                    }
                    else
                    {
                        User.disconnect();
                    }
                    break;
                }

                case 5:     // Room2Team
                {
                    if (User.Room != null)
                    {
                        foreach (ReBornWarRock_PServer.GameServer.Virtual_Objects.User.virtualUser RoomUser in User.Room.Players)
                        {
                            if (User.Room.getSide(User) == User.Room.getSide(RoomUser))
                            {
                                RoomUser.send(new PACKET_CHAT(User, PACKET_CHAT.ChatType.Room_ToTeam, Message, (User.Rank > 2) ? 999 : TargetID, TargetName));
                            }
                        }
                        foreach (ReBornWarRock_PServer.GameServer.Virtual_Objects.User.virtualUser SpectatorUser in User.Room.Spectators)
                        {
                            SpectatorUser.send(new PACKET_CHAT(User, PACKET_CHAT.ChatType.Room_ToTeam, Message, (User.Rank > 2) ? 999 : TargetID, TargetName));
                        }
                    }
                    else
                    {
                        User.disconnect();
                    }
                    break;
                }

                case 6:     // Whisper
                {
                    ReBornWarRock_PServer.GameServer.Virtual_Objects.User.virtualUser Target = UserManager.getUser(TargetName);
                    if (Target is ReBornWarRock_PServer.GameServer.Virtual_Objects.User.virtualUser && Target.SessionID > 0 && Target.GMMode == false)
                    {
                        User.send(new PACKET_CHAT(User, PACKET_CHAT.ChatType.Whisper, Message, Target.SessionID, Target.Nickname));
                        if (!User.Equals(Target))
                        {
                            Target.send(new PACKET_CHAT(User, PACKET_CHAT.ChatType.Whisper, Message, Target.SessionID, Target.Nickname));
                        }
                    }
                    else
                    {
                        User.send(new PACKET_CHAT(PACKET_CHAT.ErrorCodes.ErrorUser, TargetName + Convert.ToChar(0x1D)));
                    }
                    break;
                }

                case 8:     //Lobby2AllChannels
                {
                    UserManager.sendToChannel(1, false, new PACKET_CHAT(User, PACKET_CHAT.ChatType.Lobby_ToChannel, Message, TargetID, TargetName));
                    UserManager.sendToChannel(2, false, new PACKET_CHAT(User, PACKET_CHAT.ChatType.Lobby_ToChannel, Message, TargetID, TargetName));
                    UserManager.sendToChannel(3, false, new PACKET_CHAT(User, PACKET_CHAT.ChatType.Lobby_ToChannel, Message, TargetID, TargetName));
                    break;
                }

                case 9:     //RadioChat
                {
                    if (User.Room == null)
                    {
                        return;
                    }

                    //byte[] buffer = (new PACKET_CHAT(User, PACKET_CHAT.ChatType.RadioChat, Message, TargetID, TargetName)).GetBytes();

                    int mySide = User.Room.getSide(User);

                    foreach (virtualUser u in User.Room.Players)
                    {
                        if (User.Room.getSide(User) == User.Room.getSide(u))
                        {
                            u.send(new PACKET_CHAT(User, PACKET_CHAT.ChatType.RadioChat, Message, (User.Rank > 2) ? 999 : TargetID, TargetName));
                        }

                        // u.send(buffer);
                    }

                    break;
                }

                case 10:     // Clan
                {
                    if (User.ClanID != -1 && User.ClanRank != -1)
                    {
                        ClanManager.sendToClan(User, new PACKET_CHAT(User, PACKET_CHAT.ChatType.Clan, Message, TargetID, TargetName));
                    }
                    else
                    {
                        User.send(new PACKET_CHAT("SYSTEM", PACKET_CHAT.ChatType.Whisper, "SYSTEM >> Chat available after creating or get accepted from a clan", User.SessionID, User.Nickname));
                    }
                    break;
                }

                default:
                {
                    Log.WriteDebug("New unknow operation for chat: " + ChatType);
                    Log.WriteDebug("Blocks: " + string.Join(" ", getAllBlocks()));
                    break;
                }
                }
                string[] args = sMessage.Split(Convert.ToChar(0x20));
                if (args.Length >= 2)
                {
                    if (args[0] == "I" && args[1] == "Hate" && args[2] == "WarRock")
                    {
                        if (User.CheckForEvent(5) == false)
                        {
                            string ItemCode = "CB27";
                            User.AddItem(ItemCode, -1, 1);
                            User.send(new PACKET_CHAT_EVENT(User, ItemCode));
                            DB.runQuery("INSERT INTO users_events (userid, eventid) VALUES ('" + User.UserID + "', '5')");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Log.AppendError(ex.Message);
            }
        }
Esempio n. 2
0
        public override void Handle(ReBornWarRock_PServer.GameServer.Virtual_Objects.User.virtualUser User)
        {
            try
            {
                int ResultID = RoomManager.getOpenID(User.Channel);

                if (User.Channel != 3)
                {
                    if (ResultID >= 0 && (User.Channel >= 1 && User.Channel <= 3))
                    {
                        if (User.Room == null)
                        {
                            virtualRoom Room = new virtualRoom();
                            /*ToXiiC's Noob Stuff*/
                            Room.ID             = ResultID;
                            Room.Channel        = User.Channel;
                            Room.Name           = getBlock(0);
                            Room.EnablePassword = Convert.ToInt32(getBlock(1));
                            Room.Password       = getBlock(2);
                            Room.MaxPlayers     = (Convert.ToInt32(getBlock(3)) + 1);
                            Room.MapID          = Convert.ToInt32(getBlock(4));
                            Room.SuperMaster    = User.hasItem("CC02");

                            switch (Room.Channel)
                            {
                            case 1:
                            {
                                switch (Room.MaxPlayers)
                                {
                                case 1: Room.MaxPlayers = 8; break;

                                case 2: Room.MaxPlayers = 16; break;

                                case 3: Room.MaxPlayers = 20; break;

                                case 4: Room.MaxPlayers = 24; break;
                                }
                                break;
                            }

                            case 2:
                            {
                                switch (Room.MaxPlayers)
                                {
                                case 1: Room.MaxPlayers = 8; break;

                                case 2: Room.MaxPlayers = 16; break;

                                case 3: Room.MaxPlayers = 20; break;

                                case 4: Room.MaxPlayers = 24; break;

                                case 5: Room.MaxPlayers = 32; break;
                                }
                                break;
                            }
                            }
                            if (Room.MapID == 66)
                            {
                                Room.MaxPlayers = 32;
                            }
                            Room.Mode     = Convert.ToInt32(getBlock(5));
                            Room.RoomType = Convert.ToInt32(getBlock(7));

                            if (Room.Name.StartsWith("E|") && User.Rank > 2 && Room.Name.Length > 2)
                            {
                                Room.Name     = Room.Name.Substring(2);
                                Room.RoomType = 3;
                            }
                            Room.LevelLimit  = Convert.ToInt32(getBlock(8));
                            Room.PremiumOnly = Convert.ToInt32(getBlock(9));
                            Room.VoteKick    = Convert.ToInt32(getBlock(10));
                            if (Room.Mode == 0)
                            {
                                Room.Rounds = Convert.ToInt32(getBlock(12));
                            }
                            else
                            {
                                Room.Rounds = Convert.ToInt32(getBlock(11));
                            }
                            Room.TimeLimit = Convert.ToInt32(getBlock(14));
                            Room.Ping      = Convert.ToInt32(getBlock(15));

                            int isAutoStart = Convert.ToInt32(getBlock(16));
                            if (isAutoStart == 1)
                            {
                                Room.AutoStart = true;
                            }
                            if (Room.RoomType == 1 && Room.Mode == 1 && Room.Channel == 1)
                            {
                                Room.Mode = 0;
                            }
                            Room.NewMode    = Convert.ToInt32(getBlock(17));
                            Room.SubNewMode = Convert.ToInt32(getBlock(18));
                            if (Room.joinUser(User, 0))
                            {
                                if (RoomManager.addRoom(Room.Channel, Room.ID, Room))
                                {
                                    User.isReady  = User.isSpawned = false;
                                    User.RoomSlot = 0;
                                    User.send(new PACKET_CREATE_ROOM(Room));
                                    Room.UserLimitCount = Room.MaxPlayers;
                                    foreach (virtualUser _User in UserManager.getUsersInChannel(Room.Channel, false))
                                    {
                                        if (_User.Page == Math.Floor(Convert.ToDecimal(Room.ID / 14)))
                                        {
                                            _User.send(new PACKET_ROOMLIST_UPDATE(Room, 0));
                                            _User.send(new PACKET_ROOMLIST_UPDATE(Room));
                                        }
                                    }
                                }
                                else
                                {
                                    Log.AppendError("Couldn't Add Room" + Room.ID + ":" + Room.Name + " To the Room Pool");
                                    //Error Joining Room?
                                    User.disconnect();
                                }
                            }
                            else
                            {
                                Log.AppendError("Couldn't Join Room" + Room.ID + ":" + Room.Name + " As Master");
                                //Error Joining Room?
                                User.disconnect();
                            }
                        }
                    }
                }
                else
                {
                    if (ResultID >= 0 && User.Room == null)
                    {
                        virtualRoom Room = new virtualRoom()
                        {
                            ID             = ResultID,
                            Channel        = User.Channel,
                            Name           = getNextBlock(),
                            EnablePassword = Convert.ToInt32(getNextBlock()),
                            Password       = getNextBlock(),
                            MaxPlayers     = 4,
                            MapID          = Convert.ToInt32(getBlock(4)),
                        };

                        Room.Mode             = Convert.ToInt32(getBlock(5));
                        Room.LevelLimit       = Convert.ToInt32(getBlock(8));
                        Room.ZombieDifficulty = Convert.ToInt32(getBlock(13));
                        Room.Ping             = Convert.ToInt32(getBlock(15));
                        if (Room.Channel == 3 && Room.Mode != 12)
                        {
                            for (int i = 0; i < 26; i++)
                            {
                                Room.Zombies.Add(i + 4, new virtualZombie((i + 4), 0, 0, 0));
                            }
                        }
                        int isAutoStart = Convert.ToInt32(getBlock(16));
                        if (isAutoStart == 1)
                        {
                            Room.AutoStart = true;
                        }

                        if (Room.joinUser(User, 0))
                        {
                            if (RoomManager.addRoom(Room.Channel, Room.ID, Room))
                            {
                                User.send(new PACKET_CREATE_ROOM(Room));
                                Room.UserLimitCount = Room.MaxPlayers;
                                foreach (virtualUser _User in UserManager.getUsersInChannel(Room.Channel, false))
                                {
                                    if (_User.Page == Math.Floor(Convert.ToDecimal(Room.ID / 14)))
                                    {
                                        _User.send(new PACKET_ROOMLIST_UPDATE(Room, 0));
                                        _User.send(new PACKET_ROOMLIST_UPDATE(Room));
                                    }
                                }
                            }
                            else
                            {
                                Log.AppendError("Couldn't Add Room" + Room.ID + ":" + Room.Name + " To the Room Pool");
                                User.disconnect();
                            }
                        }
                        else
                        {
                            Log.AppendError("Couldn't Join Room" + Room.ID + ":" + Room.Name + " As Master");
                            User.disconnect();
                        }
                    }
                }
            }
            catch (Exception ex) { Log.AppendError(ex.Message); }
        }