public override void Execute(GameClient Client, byte* pPacket)
        {
            AuthMessage* Message = (AuthMessage*)pPacket;
            uint Token = Message->AccountID | 0xAABB;
            Token = Message->AccountID << 8 | Message->AccountID;
            Token = Token ^ 0x4321;
            Token = Token << 8 | Token;

            if (Token == Message->LoginToken)
            {
                Client.UID = Message->AccountID;

                Client.GenerateKeys(Message->LoginToken, Message->AccountID);
                if (Database.GetCharacterData(Client))
                {
                    Chat* Response = PacketHelper.CreateChat("SYSTEM", "ALLUSERS", "ANSWER_OK");
                    Response->ChatType = ChatType.LoginInformation;
                    Response->ID = Message->AccountID;
                    Client.Send(Response, Response->Size);
                    Memory.Free(Response);

                    CharacterInformation* Information = PacketHelper.CreateInformation(Client);
                    Client.Send(Information, Information->Size);
                    Memory.Free(Information);

                    EntityManager.Add(Client);
                    Client.Status = LoginStatus.Complete;
                }
                else
                {
                    Chat* Response = PacketHelper.CreateChat("SYSTEM", "ALLUSERS", "NEW_ROLE");
                    Response->ChatType = ChatType.LoginInformation;
                    Response->ID = Message->AccountID;
                    Client.Send(Response, Response->Size);
                    Memory.Free(Response);
                }

            }
            else
            {
                Client.Disconnect();
            }
        }
Esempio n. 2
0
 public override void Execute(GameClient Client, byte* pPacket)
 {
     ItemUsage* Packet = (ItemUsage*)pPacket;
     switch (Packet->UsageID)
     {
         case ItemUsageIDs.Ping: Client.Send(Packet, Packet->Size); break;
         case ItemUsageIDs.Equip: HandleEquip(Client, Packet); break;
         case ItemUsageIDs.UnequipItem: HandleUnequip(Client, Packet); break;
     }
 }
Esempio n. 3
0
 public void Client2Connect(GameClient c2)
 {
     this.client2           = c2;
     this.client1.onPacket += this.PacketListener;
     this.client2.onPacket += this.PacketListener;
     c2.Send(new ConnectAckPacket(1, c2.Id, this.roomId));
     this.emitGameBegin();
     Console.WriteLine("Game Room " + this.roomId + " begins Game!");
     c2.setIngame(this.roomId);
 }
Esempio n. 4
0
        public override void Execute(GameClient Client, byte *pPacket)
        {
            AuthMessage *Message = (AuthMessage *)pPacket;
            uint         Token   = Message->AccountID | 0xAABB;

            Token = Message->AccountID << 8 | Message->AccountID;
            Token = Token ^ 0x4321;
            Token = Token << 8 | Token;

            if (Token == Message->LoginToken)
            {
                Client.UID = Message->AccountID;

                Client.GenerateKeys(Message->LoginToken, Message->AccountID);
                if (Database.GetCharacterData(Client))
                {
                    Chat *Response = PacketHelper.CreateChat("SYSTEM", "ALLUSERS", "ANSWER_OK");
                    Response->ChatType = ChatType.LoginInformation;
                    Response->ID       = Message->AccountID;
                    Client.Send(Response, Response->Size);
                    Memory.Free(Response);

                    CharacterInformation *Information = PacketHelper.CreateInformation(Client);
                    Client.Send(Information, Information->Size);
                    Memory.Free(Information);

                    EntityManager.Add(Client);
                    Client.Status = LoginStatus.Complete;
                }
                else
                {
                    Chat *Response = PacketHelper.CreateChat("SYSTEM", "ALLUSERS", "NEW_ROLE");
                    Response->ChatType = ChatType.LoginInformation;
                    Response->ID       = Message->AccountID;
                    Client.Send(Response, Response->Size);
                    Memory.Free(Response);
                }
            }
            else
            {
                Client.Disconnect();
            }
        }
Esempio n. 5
0
        public void EndStatusUpdates()
        {
            lock (PendingUpdates)
            {
                StatusUpdateEntry[] Entries = PendingUpdates.Values.ToArray();
                StatusUpdate *      Update  = PacketHelper.UpdatePacket(Entries);
                Update->UID = UID;
                Owner.Send(Update, Update->Size);
                Memory.Free(Update);

                PendingUpdates.Clear();
            }
        }
Esempio n. 6
0
        public override void Execute(GameClient Client, byte *pPacket)
        {
            ItemUsage *Packet = (ItemUsage *)pPacket;

            switch (Packet->UsageID)
            {
            case ItemUsageIDs.Ping: Client.Send(Packet, Packet->Size); break;

            case ItemUsageIDs.Equip: HandleEquip(Client, Packet); break;

            case ItemUsageIDs.UnequipItem: HandleUnequip(Client, Packet); break;
            }
        }
Esempio n. 7
0
        private static void ReconnectHandler(GameClient client, BinaryReader br)
        {
            int reconID = br.ReadInt32();

            if (_clients.ContainsKey(reconID))
            {
                _clients[reconID].Disconnect();
                _clients.Remove(reconID);
            }
            //give client back old id
            _clients[client] = reconID;
            client.id        = reconID;
            client.Send(new GameMsg((byte)MsgType.Reconnect, client.id));
        }
Esempio n. 8
0
        public bool Add(Entity Entity)
        {
            lock (PlayerDictionary)
            {
                if (!PlayerDictionary.ContainsKey(Entity.UID))
                {
                    EntitySpawn Spawn = PacketHelper.EntitySpawn(Entity);
                    Client.Send(&Spawn, Spawn.Size);

                    PlayerDictionary.Add(Entity.UID, Entity);
                    Entity[] tmp = new Entity[PlayerDictionary.Count];
                    PlayerDictionary.Values.CopyTo(tmp, 0);
                    ScreenPlayers = tmp;
                    return(true);
                }
            }
            return(false);
        }
Esempio n. 9
0
 public override void Execute(GameClient Client, byte* pPacket)
 {
     GeneralData* Packet = (GeneralData*)pPacket;
     System.Console.WriteLine(Packet->DataID.ToString());
     switch (Packet->DataID)
     {
         case GeneralDataID.SetLocation: HandleSetLocation(Client, Packet); break;
         case GeneralDataID.Jump: HandleJumping(Client, Packet); break;
         case GeneralDataID.GetSurroundings: HandleGetSurroundings(Client, Packet); break;
         case GeneralDataID.ChangeAction: HandleChangeAction(Client, Packet); break;
         case GeneralDataID.ChangeAngle: HandleChangeAngle(Client, Packet); break;
         case GeneralDataID.EnterPortal: HandlePortal(Client, Packet); break;
         case GeneralDataID.ChangeAvatar: HandleChangeAvatar(Client, Packet); break;
         case GeneralDataID.ConfirmSpells: HandleSpells(Client, Packet); break;
         default:
             Client.Send(Packet, Packet->Size);
             break;
     }
 }
Esempio n. 10
0
 public GameRoom(GameServerRunner server, int roomId, GameClient c1)
 {
     this.server = server;
     for (int x = 0; x < 7; x++)
     {
         for (int y = 0; y < 6; y++)
         {
             fieldState[x, y] = 0;
         }
     }
     this.client1 = c1;
     this.roomId  = roomId;
     c1.RoomId    = roomId;
     Console.WriteLine("New Gameroom Created! Player 1: " + c1.Name);
     //Room Sends Connect Ack
     c1.Send(new ConnectAckPacket(0, c1.Id, roomId));
     this.client2 = null;
     this.state   = RoomStates.WAITING;
     c1.setIngame(this.roomId);
 }
Esempio n. 11
0
        public override void Execute(GameClient Client, byte *pPacket)
        {
            Chat *Packet = (Chat *)pPacket;

            string[] Parameters = PacketHelper.ParseChat(Packet);

            CommandAction Action = CommandAction.None;

            if ((Action = CommandProcessor.Process(Client, Parameters)) != CommandAction.None)
            {
                if (Action == CommandAction.Processed)
                {
                }
                else if (Action == CommandAction.ClearNpcScripts)
                {
                    NpcScriptEngine.Clear();
                }
                return;
            }

            switch (Packet->ChatType)
            {
            case ChatType.Talk:
                Client.SendScreen(Packet, Packet->Size);
                break;

            case ChatType.Whisper:
                GameClient Receiver = EntityManager.FindByName(Parameters[1]);
                if (Receiver != null)
                {
                    Receiver.Send(Packet, Packet->Size);
                }
                else
                {
                    Client.Message("It appears that " + Parameters[1] + " is offline", ChatType.Top, Color.White);
                }
                break;
            }
        }
Esempio n. 12
0
        private void HandleJumping(GameClient Client, GeneralData *Packet)
        {
            ushort X1 = Packet->ValueA;
            ushort Y1 = Packet->ValueB;

            if ((X1 != Client.Entity.Location.X) || (Y1 != Client.Entity.Location.Y))
            {
                Client.Disconnect();
            }
            else
            {
                ushort X2 = Packet->ValueD_High;
                ushort Y2 = Packet->ValueD_Low;

                Client.Entity.Angle = ConquerMath.GetAngle(Client.Entity.Location, new Location()
                {
                    X = X2, Y = Y2
                });

                Client.Entity.Location.X = X2;
                Client.Entity.Location.Y = Y2;

                if (!Kernel.IsWalkable(Client.Entity.Location.MapID,
                                       Client.Entity.Location.X, Client.Entity.Location.Y))
                {
                    Client.Disconnect();
                }
                else
                {
                    Client.Send(Packet, Packet->Size);

                    Client.SendScreen(Packet, Packet->Size);
                    Kernel.GetScreen(Client, ConquerCallbackKernel.GetScreenReply);
                }
            }
        }
Esempio n. 13
0
        public static void GetScreen(GameClient Client, ConquerCallback Callback)
        {
            Client.Screen.Cleanup();

            try
            {
                EntityManager.AcquireLock();

                int Distance = -1;

                GameClient[] Clients = EntityManager.Clients;
                foreach (GameClient Other in Clients)
                {
                    if (Other == null)
                    {
                        continue;
                    }
                    if (Other.UID == Client.UID)
                    {
                        continue;
                    }
                    if (Other.Entity.Location.MapID != Client.Entity.Location.MapID)
                    {
                        continue;
                    }

                    Distance = ConquerMath.CalculateDistance(Other.Entity.Location, Client.Entity.Location);
                    if (Distance <= ScreenView)
                    {
                        if (Client.Screen.Add(Other.Entity))
                        {
                            if (Callback != null)
                            {
                                Callback(Client.Entity, Other.Entity);
                            }
                        }
                    }
                }

                NonPlayerCharacter[] NPCs = EntityManager.GetNonPlayingCharacters(Client.Entity.Location.MapID);
                if (NPCs != null)
                {
                    foreach (NonPlayerCharacter npc in NPCs)
                    {
                        if (npc.Location.MapID != Client.Entity.Location.MapID)
                        {
                            continue;
                        }
                        Distance = ConquerMath.CalculateDistance(npc.Location, Client.Entity.Location);
                        if (Distance <= ScreenView)
                        {
                            if (Client.Screen.Add(npc))
                            {
                                NpcSpawn Spawn = npc.GetSpawnPacket();
                                Client.Send(&Spawn, Spawn.Size);
                            }
                        }
                    }
                }
            }
            finally
            {
                EntityManager.ReleaseLock();
            }
        }
Esempio n. 14
0
        public static void GetScreen(GameClient Client, ConquerCallback Callback)
        {
            Client.Screen.Cleanup();

            try
            {
                EntityManager.AcquireLock();

                int Distance = -1;

                GameClient[] Clients = EntityManager.Clients;
                foreach (GameClient Other in Clients)
                {
                    if (Other == null) continue;
                    if (Other.UID == Client.UID) continue;
                    if (Other.Entity.Location.MapID != Client.Entity.Location.MapID) continue;

                    Distance = ConquerMath.CalculateDistance(Other.Entity.Location, Client.Entity.Location);
                    if (Distance <= ScreenView)
                    {
                        if (Client.Screen.Add(Other.Entity))
                        {
                            if (Callback != null)
                            {
                                Callback(Client.Entity, Other.Entity);
                            }
                        }
                    }
                }

                NonPlayerCharacter[] NPCs = EntityManager.GetNonPlayingCharacters(Client.Entity.Location.MapID);
                if (NPCs != null)
                {
                    foreach (NonPlayerCharacter npc in NPCs)
                    {
                        if (npc.Location.MapID != Client.Entity.Location.MapID) continue;
                        Distance = ConquerMath.CalculateDistance(npc.Location, Client.Entity.Location);
                        if (Distance <= ScreenView)
                        {
                            if (Client.Screen.Add(npc))
                            {
                                NpcSpawn Spawn = npc.GetSpawnPacket();
                                Client.Send(&Spawn, Spawn.Size);
                            }
                        }
                    }
                }
            }
            finally
            {
                EntityManager.ReleaseLock();
            }
        }
Esempio n. 15
0
        private void HandleJumping(GameClient Client, GeneralData* Packet)
        {
            ushort X1 = Packet->ValueA;
            ushort Y1 = Packet->ValueB;

            if ((X1 != Client.Entity.Location.X) || (Y1 != Client.Entity.Location.Y))
            {
                Client.Disconnect();
            }
            else
            {
                ushort X2 = Packet->ValueD_High;
                ushort Y2 = Packet->ValueD_Low;

                Client.Entity.Angle = ConquerMath.GetAngle(Client.Entity.Location, new Location() { X = X2, Y = Y2 });

                Client.Entity.Location.X = X2;
                Client.Entity.Location.Y = Y2;

                if (!Kernel.IsWalkable(Client.Entity.Location.MapID,
                    Client.Entity.Location.X, Client.Entity.Location.Y))
                {
                    Client.Disconnect();
                }
                else
                {

                    Client.Send(Packet, Packet->Size);

                    Client.SendScreen(Packet, Packet->Size);
                    Kernel.GetScreen(Client, ConquerCallbackKernel.GetScreenReply);
                }
            }
        }
Esempio n. 16
0
 private static void ConnectHandler(GameClient client, BinaryReader br)
 {
     //send client id
     client.Send(new GameMsg((byte)MsgType.Connect, client.id));
 }
Esempio n. 17
0
        private void HandleSpells(GameClient Client, GeneralData* Packet)
        {
            Database.LoadSpells(Client);
            Database.LoadProfiencys(Client);

            Client.Send(Packet, Packet->Size);
        }
Esempio n. 18
0
 private void HandleSetLocation(GameClient Client, GeneralData* Packet)
 {
     Packet->ValueA = Client.Entity.Location.X;
     Packet->ValueB = Client.Entity.Location.Y;
     Packet->ValueD_High = Client.Entity.Location.MapID;
     Client.Send(Packet, Packet->Size);
 }