PageRenderTime 355ms CodeModel.GetById 141ms app.highlight 10ms RepoModel.GetById 202ms app.codeStats 0ms

/Trunk/WorldServer/Packets/Client/System.cs

http://aioncxx.codeplex.com
C# | 209 lines | 166 code | 27 blank | 16 comment | 20 complexity | 8c53b9ab8cf32ed7adb0af0ec5ae456c MD5 | raw file
  1/* Copyright (c) 2011-2012, Zetatron Consulting
  2All rights reserved.
  3
  4Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
  5
  6* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  7
  8* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  9
 10* Neither the name of Zetatron Consulting nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
 11
 12THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 13*/
 14using System;
 15using System.Collections.Generic;
 16using System.Linq;
 17using System.Text;
 18using AionCxxLibrary.Packets;
 19using AionCxxLibrary.Utilities;
 20using AionCxxLibrary.Enums;
 21using WorldServer.Packets.Server;
 22using AionCxxLibrary.DAO;
 23using WorldServer.Services;
 24using WorldServer.DAO;
 25using WorldServer.Models;
 26
 27namespace WorldServer.Packets.Client
 28{
 29    public class CPkt_ClientVersion : AionClientPacket
 30    {
 31        public override void ProcessPacket()
 32        {
 33            Connection.SendPacket(new SPkt_ServerVersion());
 34        }
 35    }
 36
 37    public class CPkt_MACAddress : AionClientPacket
 38    {
 39        public override void ProcessPacket()
 40        {
 41            ReadBytes(22);
 42            string mac = ReadString();
 43            Log.Debug(Connection.GetRemoteIP() + " <=> " + mac);
 44        }
 45    }
 46
 47    public class CPkt_MACAddressUpdate : AionClientPacket
 48    {
 49        public override void ProcessPacket()
 50        {
 51            
 52        }
 53    }
 54
 55    public class CPkt_Login : AionClientPacket
 56    {
 57        public override void ProcessPacket()
 58        {
 59            int KeyWorld2 = ReadInt();
 60            int KeyWorld1 = ReadInt();
 61            int AccountID = ReadInt();
 62            int KeyLogin = ReadInt();
 63
 64            bool Authed = false;
 65            bool CloseAfter = true;
 66
 67            // account id 8 = xita, for debugging, when I reboot GS (clear reconnecting account table) i stay on LS (realm list) so I don't restart client every time, so PollAccount will fail ;)
 68            if (KeyWorld1 == 0 && KeyWorld2 == 0 && AccountID > 0 && KeyLogin > 0 && (NetworkService.PollReconnectingAccount(AccountID) || AccountID == 8) && AccountDAO.CheckSession(AccountID, KeyLogin))
 69                Authed = true;
 70            else if (AccountDAO.CheckSession(AccountID, KeyLogin, KeyWorld1, KeyWorld2))
 71                Authed = true;
 72            else
 73                Log.Warn(Connection.GetRemoteIP() + " failed to authenticate with " + AccountID + "/" + KeyLogin + "/" + KeyWorld1 + "/" + KeyWorld2);
 74
 75            if (Authed)
 76            {
 77                Connection.account = AccountDAO.LoadAccount(AccountID);
 78                WorldConnection wc = (WorldConnection)Connection;
 79                wc.Keys[0] = KeyLogin;
 80                wc.Keys[1] = KeyWorld1;
 81                wc.Keys[2] = KeyWorld2;
 82                CloseAfter = false;
 83            }
 84
 85            Connection.SendPacket(new SPkt_Login());
 86
 87            if (CloseAfter)
 88            {
 89                Connection.Close();
 90            }
 91
 92        }
 93    }
 94
 95    public class CPkt_Time : AionClientPacket
 96    {
 97        public override void ProcessPacket()
 98        {
 99            Connection.SendPacket(new SPkt_Time(ReadInt()));
100        }
101    }
102
103    public class CPkt_ChooseServer : AionClientPacket
104    {
105        static Random rnd = new Random();
106
107        public override void ProcessPacket()
108        {
109            int key = rnd.Next();
110            WorldConnection wc = ((WorldConnection)Connection);
111            AccountDAO.UpdateSession(wc.account.ID, wc.Keys[0], wc.Keys[1], wc.Keys[2], key);
112            NetworkService.AddReconnectingAccount(wc.account.ID);
113            Connection.SendPacket(new SPkt_ChooseServer(key));
114        }
115    }
116
117    public class CPkt_KeepAlive : AionClientPacket
118    {
119        public override void ProcessPacket()
120        {
121            Connection.SendPacket(new SPkt_KeepAlive());
122        }
123    }
124
125    public class CPkt_EnterWorldCheck : AionClientPacket
126    {
127        public override void ProcessPacket()
128        {
129            Connection.SendPacket(new SPkt_EnterWorldCheck());
130        }
131    }
132
133    public class CPkt_ClientSettings : AionClientPacket
134    {
135        public override void ProcessPacket()
136        {
137            byte type = ReadByte(); // 0 = Settings - 1 = Quick Bars
138            ReadShort();
139            ReadShort();
140            byte[] data = ReadBytes((int)(Length - Position));
141            CharacterDAO.UpdateSettings(((WorldConnection)Connection).Character.Template.ID, type, data);
142        }
143    }
144
145    public class CPkt_WorldQuit : AionClientPacket
146    {
147        public override void ProcessPacket()
148        {
149            byte action = ReadByte();
150
151            CharacterService.OnDisconnect(((WorldConnection)Connection).Character);
152            ((WorldConnection)Connection).Character = null;
153
154            Connection.SendPacket(new SPkt_WorldQuit(false), action == 0);
155        }
156    }
157
158    public class CPkt_WorldQuitInit : AionClientPacket
159    {
160        public override void ProcessPacket()
161        {
162            
163        }
164    }
165
166    public class CPkt_UIQuestionResponse : AionClientPacket
167    {
168        public override void ProcessPacket()
169        {
170            int QuestionID = ReadInt();
171            byte Response = ReadByte();
172            (Connection as WorldConnection).Character.UI.QuestionResponse(QuestionID, Response == 1);
173        }
174    }
175
176    public class CPkt_TargetChange : AionClientPacket
177    {
178        public override void ProcessPacket()
179        {
180            int TargetGUID = ReadInt();
181            byte type = ReadByte();
182
183            AionObject target;
184            try
185            {
186                target = LevelService.Objects[TargetGUID];
187            }
188            catch (Exception)
189            {
190                target = null;
191            }
192
193            if (target == null)
194            {
195                (Connection as WorldConnection).Character.Target = null;
196            }
197            else
198            {
199                if (type == 1)
200                    (Connection as WorldConnection).Character.Target = target.Target;
201                else
202                    (Connection as WorldConnection).Character.Target = target;
203            }
204            // Send Player Packet
205            // Broadcast NearbyTargetUpdate
206        }
207    }
208
209}