Esempio n. 1
0
        public static void ProcessBuyItem(Client pClient, PacketReader pPacket)
        {
            var uid = pPacket.ReadUInt64();
            var itemid = pPacket.ReadInt32();
            Item item = null;
            var result = Results.Accepted;

            item = Program.mItems.Find(i => i.nItemID == itemid);
            if (item == null)
                result = Results.ShopItemNonExistant;
            else if (item.nPrice > pClient.mCharacter.nBP)
                result = Results.ShopInsufficientBounty;
            else
            {
                Item temp = new Item();
                temp.nItemID = item.nItemID;
                temp.nLevel = item.nLevel;
                temp.nMaxWT = item.nMaxWT;
                temp.nWeight = item.nWeight;
                temp.nPrice = item.nPrice;
                Database.Execute(string.Format("INSERT INTO CharacterItem (CID,ItemID,RegDate) VALUES ({0},{1},GetDate())", pClient.mCharacter.nCID, item.nItemID));
                temp.nItemCID = Database.GetIdentity(string.Format("select @@identity"));
                pClient.mCharacter.nItems.Add(temp);

                pClient.mCharacter.nBP -= item.nPrice;
                Database.Execute(string.Format("UPDATE Character SET BP={0} WHERE CID={1}", pClient.mCharacter.nBP, pClient.mCharacter.nCID));
            }

            PacketWriter pResponseBuyItem = new PacketWriter(Operation.MatchResponseBuyItem, CryptFlags.Decrypt);
            pResponseBuyItem.Write((Int32)result);
            pClient.Send(pResponseBuyItem);
        }
Esempio n. 2
0
        public static void ResponseChannelList(Client pClient, PacketReader pPacket)
        {
            var uid = pPacket.ReadUInt64();
            var type = pPacket.ReadInt32();

            if (!Enum.IsDefined(typeof(MMatchChannelType), (byte)type))
            {
                pClient.Disconnect();
                return;
            }

            List<MMatchChannel> channels = Program.mChannels.FindAll (c => c.nChannelType == (MMatchChannelType)type);
            if (channels == null || channels.Count == 0)
                return;

            PacketWriter pChannelList = new PacketWriter(Operation.ChannelList, CryptFlags.Encrypt);
            pChannelList.Write(channels.Count, 88);
            Int16 index = 0;

            foreach (MMatchChannel c in channels)
            {
                pChannelList.Write(c.uidChannel);
                pChannelList.Write(++index);
                pChannelList.Write((Int16)c.lClients.Count);
                pChannelList.Write((Int16)c.nMaxUsers);
                pChannelList.Write((Int16)c.nMinLevel);
                pChannelList.Write((Int16)c.nMaxLevel);
                pChannelList.Write((byte)c.nChannelType);
                pChannelList.Write(c.szName, 64);
                pChannelList.Write(false);
                pChannelList.Write((Int32)0);
            }
            pClient.Send(pChannelList);
        }
Esempio n. 3
0
        public static void ResponseChannelJoinFromName(Client pClient, PacketReader pPacket)
        {
            var uid = pPacket.ReadUInt64();
            var type = pPacket.ReadInt32();
            var name = pPacket.ReadString();

            if (!Enum.IsDefined(typeof(MMatchChannelType), (byte)type))
            {
                pClient.Disconnect();
                return;
            }

            MMatchChannel channel = Program.mChannels.Find(c => c.nChannelType == (MMatchChannelType)type && c.szName.Equals(name));
            if (channel == null)
            {
                channel = new MMatchChannel();
                channel.szName = name;
                channel.lClients = new List<Client>();
                channel.nChannelRule = MMatchChannelRule.Elite;
                channel.nChannelType = (MMatchChannelType)type;
                channel.nMaxLevel = 100;
                channel.nMinLevel = 0;
                channel.nMaxUsers = 200;
                channel.uidChannel = (UInt64)Program.mChannels.Count;
                lock (Program.mChannels)
                    Program.mChannels.Add(channel);
            }
            ChannelMgr.Join(pClient, channel);
        }
Esempio n. 4
0
 public static void ProcessLiveCheck(Client pClient, PacketReader pPacket)
 {
     var timeStamp = pPacket.ReadInt32();
     PacketWriter pResponseLiveCheck = new PacketWriter(Operation.MatchAgentResponseLiveCheck, CryptFlags.Encrypt);
     pResponseLiveCheck.Write(timeStamp);
     pClient.Send(pResponseLiveCheck);
 }
Esempio n. 5
0
 public static void ProcessRegisterAgent(Client pClient, PacketReader pPacket)
 {
     pClient.mIsAgent = true;
     Log.Write("[{0}] Agent Registered.", pClient.mClientIP);
     lock (Program.mAgents)
         Program.mAgents.Add(pClient);
 }
Esempio n. 6
0
        public static void ProcessGameTimeSync(Client client, PacketReader pPacket)
        {
            var nTime = pPacket.ReadInt32();

            PacketWriter packet = new PacketWriter(Operation.GameResponseTimeSync, CryptFlags.Encrypt);
            packet.Write(nTime);
            packet.Write(Program.timeGetTime());
            client.Send(packet);
        }
Esempio n. 7
0
        public static void ProcessCharacters(Client pClient, PacketReader pPacket)
        {
            pClient.UnloadCharacter();

            PacketWriter pResponseChars = new PacketWriter(Operation.MatchResponseAccountCharList, CryptFlags.Encrypt);
            var charCount = Database.GetQuery(string.Format("SELECT COUNT(*) FROM Character WHERE AID={0}", pClient.mAccount.nAID));
            pResponseChars.Write(charCount, 34);
            Database.GetCharacterList(pClient.mAccount.nAID, pResponseChars);
            pClient.Send(pResponseChars);
        }
Esempio n. 8
0
        public static void ResponseChannelChat(Client pClient, PacketReader pPacket)
        {
            var uidChar = pPacket.ReadUInt64();
            var uidChan = pPacket.ReadUInt64();
            var message = pPacket.ReadString();

            if (uidChar != pClient.mClientUID || uidChan != pClient.mChannel.uidChannel || message.Length > 127)
            {
                pClient.Disconnect();
                return;
            }

            ChannelMgr.Chat(pClient, message);
        }
Esempio n. 9
0
        public static void ResponseChannelJoin(Client pClient, PacketReader pPacket)
        {
            var uidChar = pPacket.ReadUInt64();
            var uidChan = pPacket.ReadUInt64();

            if (uidChar != pClient.mClientUID)
            {
                pClient.Disconnect();
                return;
            }

            MMatchChannel channel = Program.mChannels.Find(c => c.uidChannel == uidChan);
            if (channel != null)
                ChannelMgr.Join(pClient, channel);
        }
Esempio n. 10
0
        public static void ProcessCharInfo(Client pClient, PacketReader pReader)
        {
            var index = pReader.ReadByte();

            if (index < 0 || index > 4)
            {
                pClient.Disconnect();
                return;
            }

            pClient.mCharacter.nCharNum = index;
            Database.GetCharacter(pClient.mAccount.nAID, index, pClient.mCharacter);
            pClient.mCharacter.nUGradeID = pClient.mAccount.nUGradeID;

            PacketWriter pCharInfoResponse = new PacketWriter(Operation.MatchResponseAccountCharInfo, CryptFlags.Encrypt);
            pCharInfoResponse.Write(index);
            pCharInfoResponse.Write(pClient.mCharacter);
            pClient.Send(pCharInfoResponse);
        }
Esempio n. 11
0
        public static void ProcessBattleInfo(Client pClient, PacketReader pPacket)
        {
            MMatchStage stage = pClient.mStage;
            PacketWriter packet = new PacketWriter(Operation.BattleResponseInfo, CryptFlags.Encrypt);

            packet.Write(stage.uidStage);
            packet.Write(1,6);
            packet.Write(stage.nRedTeamScore);
            packet.Write(stage.nBlueTeamScore);
            packet.Write((Int32)0);
            packet.Write(0, 0);
            packet.Write(stage.Clients.Count, 17);
            foreach (Client c in stage.Clients)
            {
                packet.Write(c.mClientUID);
                packet.Write(c.mGame.Spawned);
                packet.Write(c.mGame.Kills);
                packet.Write(c.mGame.Deaths);
            }
            pClient.Send(packet);
            stage.BattleMgr.GameInfoCallback(pClient);
        }
Esempio n. 12
0
        public static void ProcessGameSpawn(Client client, PacketReader pPacket)
        {
            var uid = pPacket.ReadUInt64();
            var xpos = pPacket.ReadSingle();
            var ypos = pPacket.ReadSingle();
            var zpos = pPacket.ReadSingle();
            var xdir = pPacket.ReadSingle();
            var ydir = pPacket.ReadSingle();
            var zdir = pPacket.ReadSingle();

            PacketWriter packet = new PacketWriter(Operation.GameResponseSpawn, CryptFlags.Encrypt);
            packet.Write(client.mClientUID);
            packet.Write((UInt16)xpos);
            packet.Write((UInt16)ypos);
            packet.Write((UInt16)zpos);
            packet.Write((UInt16)xdir);
            packet.Write(new byte[] { 0xfc, 0xc7 }, 0, 2);
            packet.Write((UInt16)ydir);

            foreach (Client c in client.mStage.Clients)
                c.Send(packet);
        }
Esempio n. 13
0
        public static void ProcessCharItemList(Client pClient, PacketReader pPacket)
        {
            PacketWriter pResponseCharItems = new PacketWriter(Operation.MatchResponseCharacterItemList, CryptFlags.Decrypt);
            pResponseCharItems.Write(pClient.mCharacter.nBP);

            pResponseCharItems.Write(12, 8);
            for (int i = 0; i < 12; ++i)
            {
                pResponseCharItems.Write((Int32)0);
                pResponseCharItems.Write(pClient.mCharacter.nEquippedItems[i].nItemCID);
            }

            pResponseCharItems.Write(pClient.mCharacter.nItems.Count, 16);
            foreach (Item i in pClient.mCharacter.nItems)
            {
                pResponseCharItems.Write((Int32)0);
                pResponseCharItems.Write(i.nItemCID);
                pResponseCharItems.Write(i.nItemID);
                pResponseCharItems.Write(i.nRentHour);
            }
            pResponseCharItems.Write(0, 12);
            pClient.Send(pResponseCharItems);
        }
Esempio n. 14
0
        public static void ProcessDeleteChar(Client pClient, PacketReader pPacket)
        {
            var uid = pPacket.ReadUInt64();
            var index = pPacket.ReadInt32();
            var name = pPacket.ReadString();
            var result = Results.Accepted;

            if (uid != pClient.mClientUID || !Program.mRegex.IsMatch(name) || index < 0 || index > 4)
            {
                pClient.Disconnect();
                return;
            }

            var cid = Database.GetQuery(string.Format("SELECT CID FROM Character WHERE CharNum={0} AND AID={1}", index, pClient.mAccount.nAID));
            if (cid == 0) result = Results.CharacterDeleteDisabled;
            else
            {
                Database.Execute("DELETE FROM CharacterItem WHERE CID=" + cid);
                Database.Execute("DELETE FROM Character WHERE CID=" + cid);
                Database.UpdateIndexes(pClient.mAccount.nAID);
            }

            PacketWriter pResponseDeleteChar = new PacketWriter(Operation.MatchResponseDeleteChar, CryptFlags.Encrypt);
            pResponseDeleteChar.Write((Int32)result);
            pClient.Send(pResponseDeleteChar);
        }
Esempio n. 15
0
 public static void ProcessLoading(Client pClient, PacketReader pPacket)
 {
     if (pClient.mStage == null) return;
     pClient.mStage.BattleMgr.GameLoadedCallback(pClient);
 }
Esempio n. 16
0
 public static void ProcessEnterBattle(Client pClient, PacketReader pPacket)
 {
     if (pClient.mStage == null) return;
     pClient.mStage.BattleMgr.GameEnterCalback(pClient);
 }
Esempio n. 17
0
        public static void ProcessEquipItem(Client pClient, PacketReader pPacket)
        {
            var uidChar = pPacket.ReadUInt64();
            var nItemLow = pPacket.ReadInt32();
            var nItemHigh = pPacket.ReadInt32();
            var nItemSlot = pPacket.ReadInt32();
            Results result = Results.Accepted;

            if (!Enum.IsDefined(typeof(MMatchItemSlotType), nItemSlot))
            {
                pClient.Disconnect();
                return;
            }

            Item nItem = pClient.mCharacter.nItems.Find(i => i.nItemCID == nItemHigh);
            if (nItem == null)
                result = Results.ShopItemNonExistant;
            else
            {
                pClient.mCharacter.nEquippedItems[nItemSlot].nItemCID = nItemHigh;
                pClient.mCharacter.nEquippedItems[nItemSlot].nItemID = nItem.nItemID;
                Database.Execute(string.Format("UPDATE Character SET {0}={1} WHERE CID={2}", (MMatchItemSlotType)nItemSlot, nItemHigh, pClient.mCharacter.nCID));
            }
            PacketWriter pResponseEquipItem = new PacketWriter(Operation.MatchResponseEquipItem, CryptFlags.Decrypt);
            pResponseEquipItem.Write((Int32)result);
            pClient.Send(pResponseEquipItem);

            ProcessCharItemList(pClient, pPacket);
        }
Esempio n. 18
0
        private void ProcessStream()
        {
            var position = 0;
            var finished = false;

            while (!finished && position < mStream.Length)
            {
                if ((mStream.Length - position) >= 6)
                {
                    byte[] bPacket = new byte[6];
                    Buffer.BlockCopy(mStream, position, bPacket, 0, 6);

                    if ((CryptFlags)bPacket[0] == CryptFlags.Encrypt)
                    {
                        PacketCrypt.Decrypt(bPacket, 2, 2, mCrypt);
                        var size = BitConverter.ToUInt16(bPacket, 2);
                        if ((mStream.Length - position) >= size)
                        {
                            Array.Resize<byte>(ref bPacket, size);
                            Buffer.BlockCopy(mStream, position, bPacket, 0, size);
                            PacketCrypt.Decrypt(bPacket, 6, size - 6, mCrypt);
                            PacketReader pReader = new PacketReader(bPacket, size);
                            lock (mPacketQueue)
                                mPacketQueue.Enqueue(pReader);
                            position += size;
                        }
                        else finished = true;
                    }
                    else if ((CryptFlags)bPacket[0] == CryptFlags.Decrypt)
                    {
                        var size = BitConverter.ToUInt16(bPacket, 2);
                        if ((mStream.Length - position) >= size)
                        {
                            Array.Resize<byte>(ref bPacket, size);
                            Buffer.BlockCopy(mStream, position, bPacket, 0, size);
                            PacketReader pReader = new PacketReader(bPacket, size);
                            lock (mPacketQueue)
                                mPacketQueue.Enqueue(pReader);
                            position += size;
                        }
                        else finished = true;

                    }
                }
                else finished = true;
            }

            var temp = new byte[mStream.Length - position];
            Buffer.BlockCopy(mStream, position, temp, 0, mStream.Length - position);
            mStream = temp;
        }
Esempio n. 19
0
        public static void ProcessLogin(Client client, PacketReader pPacket)
        {
            /* @ARGS
             * UserID - string
             * Password - string
             * CommandVersion - int
             * Checksum - int
             * MD5 - Blob
             */

            var UserID = pPacket.ReadString();
            var Password = pPacket.ReadString();
            var CommandID = pPacket.ReadInt32();
            var Checksum = pPacket.ReadInt32();
            var totalSize = pPacket.ReadInt32();
            var blobSize = pPacket.ReadInt32();
            var count = pPacket.ReadInt32();
            Results result = Results.Accepted;

            if (blobSize > 32)
            {
                client.Disconnect();
                return;
            }

            if (!Program.mRegex.IsMatch(UserID) || !Program.mRegex.IsMatch(Password))
                result = Results.LoginIncorrectPassword;
            else
            {
                Log.Write("Login: {0} {1}", UserID, Password);
                Database.GetAccount(UserID, Password, ref client.mAccount);
                if (client.mAccount.nAID == 0)
                    result = Results.LoginIncorrectPassword;
                else if (client.mAccount.nUGradeID == MMatchUserGradeID.Banned || client.mAccount.nUGradeID == MMatchUserGradeID.Penalty)
                    result = Results.LoginBannedID;
                else if (client.mAccount.nAID > 0)
                    client.mClientFlags = PacketFlags.Login;
            }
            PacketWriter pLoginResponse = new PacketWriter(Operation.MatchLoginResponse, CryptFlags.Encrypt);
            pLoginResponse.Write((Int32)result);
            pLoginResponse.Write("Lol Emu Test");
            pLoginResponse.Write((byte)2);//Moode
            pLoginResponse.Write(UserID);
            pLoginResponse.Write((byte)client.mAccount.nUGradeID);
            pLoginResponse.Write((byte)client.mAccount.nPGradeID);
            pLoginResponse.Write(client.mClientUID);
            pLoginResponse.Write(false);
            pLoginResponse.Write(1, 20);
            pLoginResponse.WriteSkip(20);
            client.Send(pLoginResponse);

            if (client.mAccount.nUGradeID == MMatchUserGradeID.Banned || client.mAccount.nUGradeID == MMatchUserGradeID.Penalty)
                client. Disconnect();
        }
Esempio n. 20
0
        public static void ProcessRequestRecommendChannel(Client pClient, PacketReader pPacket)
        {
            MMatchChannel channel = null;
            channel = Program.mChannels.Find(c => c.nMaxUsers > c.lClients.Count && c.nMinLevel < pClient.mCharacter.nLevel && c.nMaxLevel > pClient.mCharacter.nLevel);
            if (channel == null)
                channel = Program.mChannels[0];

            PacketWriter pResponseRecommendChannel = new PacketWriter(Operation.MatchResponseRecommendedChannel, CryptFlags.Encrypt);
            pResponseRecommendChannel.Write(channel.uidChannel);
            pClient.Send(pResponseRecommendChannel);
        }
Esempio n. 21
0
        public static void ProcessSelectChar(Client pClient, PacketReader pPacket)
        {
            var uid = pPacket.ReadUInt64();
            var index = pPacket.ReadInt32();

            if (uid != pClient.mClientUID || index < 0 || index > 4)
            {
                pClient.Disconnect();
                return;
            }

            PacketWriter pResponseSelectChar = new PacketWriter(Operation.MatchResponseSelectChar, CryptFlags.Encrypt);
            pResponseSelectChar.Write((Int32)0);
            pResponseSelectChar.Write(pClient.mCharacter);
            pResponseSelectChar.Write(1, 1);
            pResponseSelectChar.Write((byte)0x3E);
            pClient.Send(pResponseSelectChar);

            pClient.mClientFlags = PacketFlags.Character;
        }
Esempio n. 22
0
        public static void ProcessSellItem(Client pClient, PacketReader pPacket)
        {
            var uidChar = pPacket.ReadUInt64();
            var low = pPacket.ReadInt32();
            var high = pPacket.ReadInt32();
            var result = Results.Accepted;

            var item = pClient.mCharacter.nItems.Find (i => i.nItemCID == high);
            if (item == null)
                result = Results.ShopItemNonExistant;
            else
            {
                Database.Execute(string.Format("DELETE FROM CharacterItem WHERE CIID={0}", item.nItemCID));
                pClient.mCharacter.nBP += item.nPrice;
                Database.Execute(string.Format("UPDATE Character SET BP={0} WHERE CID={1}", pClient.mCharacter.nBP, pClient.mCharacter.nCID));
                pClient.mCharacter.nItems.Remove(item);
            }

            PacketWriter pResponseSellItem = new PacketWriter(Operation.MatchResponseSellItem, CryptFlags.Decrypt);
            pResponseSellItem.Write((Int32)result);
            pClient.Send(pResponseSellItem);
        }
Esempio n. 23
0
        public static void ProcessShopItemList(Client pClient, PacketReader pPacket)
        {
            PacketWriter pResponseShop = new PacketWriter(Operation.MatchResponseShopItemList, CryptFlags.Decrypt);
            pResponseShop.Write(1, 12);
            pResponseShop.WriteSkip(12);

            pResponseShop.Write(Program.mShop.Count, 4);
            foreach (uint item in Program.mShop)
                pResponseShop.Write(item);

            pClient.Send(pResponseShop);
        }
Esempio n. 24
0
        public static void ProcessTakeOffItem(Client pClient, PacketReader pPacket)
        {
            var uidChar = pPacket.ReadUInt64();
            var nItemSlot = pPacket.ReadInt32();

            if (!Enum.IsDefined(typeof(MMatchItemSlotType), nItemSlot))
            {
                pClient.Disconnect();
                return;
            }
            pClient.mCharacter.nEquippedItems[nItemSlot].nItemCID = 0;
            pClient.mCharacter.nEquippedItems[nItemSlot].nItemID = 0;
            Database.Execute(string.Format("UPDATE Character SET {0}={1} WHERE CID={2}", (MMatchItemSlotType)nItemSlot, 0, pClient.mCharacter.nCID));

            PacketWriter pResponseTakeOffItem = new PacketWriter(Operation.MatchResponseTakeOffItem, CryptFlags.Decrypt);
            pResponseTakeOffItem.Write((Int32)0);
            pClient.Send(pResponseTakeOffItem);

            ProcessCharItemList(pClient, null);
        }
Esempio n. 25
0
        public static void ResponsePlayerList(Client pClient, PacketReader pPacket)
        {
            var uidChar = pPacket.ReadUInt64();
            var uidChan = pPacket.ReadUInt64();
            var page = pPacket.ReadInt32();

            if (uidChar != pClient.mClientUID || uidChan != pClient.mChannel.uidChannel)
            {
                pClient.Disconnect();
                return;
            }

            pClient.mChannelPage = page;
            ChannelMgr.PlayerList(pClient);
        }
Esempio n. 26
0
        public static void ProcessCreateChar(Client pClient, PacketReader pPacket)
        {
            var uid = pPacket.ReadUInt64();
            var index = pPacket.ReadInt32();
            var name = pPacket.ReadString();
            var sex = pPacket.ReadInt32();
            var hair = pPacket.ReadInt32();
            var face = pPacket.ReadInt32();
            var costume = pPacket.ReadInt32();
            var result = Results.Accepted;

            if (uid != pClient.mClientUID || index < 0 || index > 4 || sex < 0 || sex > 1)
            {
                pClient.Disconnect();
                return;
            }

            if (!Program.mRegex.IsMatch(name))
                result = Results.CharacterEnterName;
            else if (Database.GetQuery("SELECT COUNT(AID) FROM Character WHERE AID=" + pClient.mAccount.nAID) >= 4)
                result = Results.CharacterInvalidName;
            else if (Database.GetQuery("SELECT COUNT(Name) FROM Character WHERE Name='" + name + "'") > 0)
                result = Results.CharacterNameInUse;
            else if (!Database.CreateCharacter(pClient.mAccount.nAID, (byte)index, name, sex, hair, face, costume))
                result = Results.CharacterInvalidName;

            PacketWriter pResponseCreateChar = new PacketWriter(Operation.MatchResponseCreateChar, CryptFlags.Encrypt);
            pResponseCreateChar.Write((Int32)result);
            pResponseCreateChar.Write(name);
            pClient.Send(pResponseCreateChar);
        }