Example #1
0
        public void ProcessPacket(BasePacket packet, PPType type)
        {
            if (packet.header.isCompressed == 0x01)
            {
                BasePacket.DecompressPacket(ref packet);
            }

            List <SubPacket> subPackets = packet.GetSubpackets();

            foreach (SubPacket subpacket in subPackets)
            {
                //Normal Game Opcode
                if (subpacket.header.type == 0x03)
                {
                    switch (type)
                    {
                    case PPType.Recv: HandleRecv(subpacket);
                        break;

                    case PPType.Send: HandleSend(subpacket);
                        break;
                    }
                }
            }
        }
    public override void ProcessPacket(BasePacket receivedPacket)
    {
        if (!isAuthenticated && receivedPacket.isAuthenticated())
        {
            isAuthenticated = true;
        }
        List <SubPacket> subPackets = receivedPacket.GetSubpackets();

        foreach (SubPacket subPacket in subPackets)
        {
            DoAuthenticationChecks(receivedPacket, subPacket);

            if (!receivedPacket.isAuthenticated())
            {
                Debug.Log("Not authenticated.. Do something here");
                throw new NotImplementedException();
            }
            else
            {
                switch (subPacket.gameMessage.opcode)
                {
                case ((ushort)GamePacketOpCode.NearbyActorsQuery):
                    PositionPacket pos     = new PositionPacket(subPacket.data);
                    ActorWrapper   wrapper = new ActorWrapper(pos.XPos, pos.YPos, pos.Playable, pos.ActorId);
                    GameEventManager.TriggerActorNeedsDrawing(new GameEventArgs {
                        Actor = wrapper
                    });

                    break;

                case ((ushort)GamePacketOpCode.PositionQuery):
                    PositionPacket otherCharacterPos = new PositionPacket(subPacket.data);
                    GameEventManager.TriggerPollerResponse(new GameEventArgs {
                        PollerPositionPacket = otherCharacterPos
                    });

                    break;

                case ((ushort)GamePacketOpCode.OtherPlayerDisconnected):
                    DisconnectPacket dc = new DisconnectPacket(subPacket.data);
                    Character        playerToDisconnect;
                    if (Data.drawnCharacters.TryGetValue(dc.CharacterId, out playerToDisconnect))
                    {
                        Data.drawnCharacters.Remove(dc.CharacterId);
                        destroyer.AddCharacter(playerToDisconnect);
                    }
                    break;
                }
            }
        }
    }
        public void ProcessPacket(ClientConnection client, BasePacket packet)
        {
            if ((packet.header.packetSize == 0x288) && (packet.data[0x34] == 'T'))              //Test Ticket Data
            {
                packet.DebugPrintPacket();
                //Crypto handshake
                ProcessStartSession(client, packet);
                return;
            }

            BasePacket.DecryptPacket(client.blowfish, ref packet);

            packet.DebugPrintPacket();

            List <SubPacket> subPackets = packet.GetSubpackets();

            foreach (SubPacket subpacket in subPackets)
            {
                subpacket.DebugPrintSubPacket();

                if (subpacket.header.type == 3)
                {
                    switch (subpacket.gameMessage.opcode)
                    {
                    case 0x03:
                        ProcessGetCharacters(client, subpacket);
                        break;

                    case 0x04:
                        ProcessSelectCharacter(client, subpacket);
                        break;

                    case 0x05:
                        ProcessSessionAcknowledgement(client, subpacket);
                        break;

                    case 0x0B:
                        ProcessModifyCharacter(client, subpacket);
                        break;

                    case 0x0F:
                    //Mod Retainers
                    default:
                        Program.Log.Debug("Unknown command 0x{0:X} received.", subpacket.gameMessage.opcode);
                        break;
                    }
                }
            }
        }
        public void ProcessPacket(WorldClientConnection client, BasePacket packet)
        {
            this.client = client;
            packet.debugPrintPacket();
            List <SubPacket> subPackets = packet.GetSubpackets();

            if (packet.header.connectionType == (ushort)BasePacketConnectionTypes.Connect)
            {
                ProcessConnectPackets(subPackets);
            }
            if (packet.header.connectionType == (ushort)BasePacketConnectionTypes.Zone)
            {
                processZonePackets(subPackets);
            }
        }
        public void ProcessPacket(WorldClientConnection client, BasePacket packet)
        {
            this.client = client;
            packet.debugPrintPacket();
            List <SubPacket> subPackets = packet.GetSubpackets();

            /*            if (packet.header.connectionType == (ushort)BasePacketConnectionTypes.Zone)
             *          {
             *              ProcessZonePackets(subPackets);
             *              //do zone stuff here
             *          }
             *          if (packet.header.connectionType == (ushort)BasePacketConnectionTypes.Chat)
             *          {
             *              ProcessChatPackets(subPackets);
             *              //do chat stuff here
             *          }*/

            if (packet.header.connectionType == (ushort)BasePacketConnectionTypes.Generic)
            {
                ProcessGenericPackets(subPackets);
            }
        }
Example #6
0
    /// <summary>
    /// All incoming packets are handled through this and then directed to the appropriate function
    /// </summary>
    /// <param name="receivedPacket"></param>
    public void ProcessPacket(BasePacket receivedPacket)
    {
        if (connect == null)
        {
        }

        if (receivedPacket == null)
        {
            Debug.Log("tis null");
        }

        if (!isAuthenticated && receivedPacket.isAuthenticated())
        {
            isAuthenticated = true;
        }

        List <SubPacket> subPackets = receivedPacket.GetSubpackets();

        foreach (SubPacket subPacket in subPackets)
        {
            /*  var stdOut = System.Console.Out;
             * var consoleOut = new System.IO.StringWriter();
             * System.Console.SetOut(consoleOut);
             * subPacket.debugPrintSubPacket();
             * Debug.Log(consoleOut.ToString());
             * System.Console.SetOut(stdOut);*/
            DoAuthenticationChecks(receivedPacket, subPacket);
            if (!receivedPacket.isAuthenticated())
            {
                if (subPacket.header.type == (ushort)SubPacketTypes.ErrorPacket)
                {
                    if (subPacket.gameMessage.opcode == (ushort)GamePacketOpCode.AccountError)
                    {
                        ErrorPacket ep = new ErrorPacket();
                        ep.ReadPacket(subPacket.data);
                        string msg = ep.GetErrorMessage();
                        StatusBoxHandler.statusText = msg;
                        Debug.Log("fam error packet");
                        Utils.SetAccountName(null);
                        StatusBoxHandler.readyToClose = true;
                    }
                }

                if (subPacket.gameMessage.opcode == (ushort)GamePacketOpCode.RegisterSuccess)
                {
                    StatusBoxHandler.statusText   = Encoding.Unicode.GetString(subPacket.data);
                    StatusBoxHandler.readyToClose = true;
                    break;
                }
            }
            else
            {
                if (subPacket.header.type == (ushort)SubPacketTypes.ErrorPacket)
                {
                    switch (subPacket.gameMessage.opcode)
                    {
                    case ((ushort)GamePacketOpCode.CreateCharacterError):
                    {
                        StatusBoxHandler.statusText   = "Character name has already been taken";
                        StatusBoxHandler.readyToClose = true;
                        break;
                    }
                    }
                }
                switch (subPacket.gameMessage.opcode)
                {
                //TODO: Refactor statusbox ready to close to use event system
                case ((ushort)GamePacketOpCode.AccountSuccess):
                    StatusBoxHandler.statusText   = Encoding.Unicode.GetString(subPacket.data);
                    isAuthenticated               = true;
                    loggedInSuccessfully          = true;
                    StatusBoxHandler.readyToClose = true;
                    break;

                //TODO: Refactor statusbox ready to close to use event system
                case ((ushort)GamePacketOpCode.CreateCharacter):
                    StatusBoxHandler.statusText   = Encoding.Unicode.GetString(subPacket.data);
                    StatusBoxHandler.readyToClose = true;
                    break;

                //TODO: Refactor statusbox ready to close to use event system
                case ((ushort)GamePacketOpCode.CreateCharacterSuccess):
                    StatusBoxHandler.statusText   = Encoding.Unicode.GetString(subPacket.data);
                    StatusBoxHandler.readyToClose = true;
                    break;

                //TODO: Refactor this to use event system
                case ((ushort)GamePacketOpCode.CharacterListQuery):
                    if (BitConverter.ToInt32(subPacket.data, 0) == -1)
                    {
                        CharacterLoader.serverResponseFinished = true;
                        break;
                    }
                    else
                    {
                        characterLoader.SetCharacterListFromServer(subPacket);
                        //else send each received packet to CharacterLoader to process
                    }

                    break;

                case ((ushort)GamePacketOpCode.CharacterDeleteSuccess):
                    StatusBoxHandler.statusText   = Encoding.Unicode.GetString(subPacket.data);
                    StatusBoxHandler.readyToClose = true;
                    break;

                case ((ushort)GamePacketOpCode.Acknowledgement):
                    Debug.Log("Gets here");
                    AcknowledgePacket ack = new AcknowledgePacket(subPacket.data);
                    GameEventManager.TriggerHandshakeResponseReceived(new GameEventArgs {
                        serverResponse = ack.AckSuccessful
                    });
                    //ackpacket has other data which is useful which i'm currently unsure on how to use atm
                    //anything set here won't be visible when scene is changed to world map.
                    break;


                default:
                    Debug.Log("Unknown or corrupted packet");
                    break;
                }
            }
        }
    }
Example #7
0
        public void ProcessPacket(ClientConnection client, BasePacket packet)
        {
            if (packet.header.isCompressed == 0x01)
            {
                BasePacket.DecompressPacket(ref packet);
            }

            List <SubPacket> subPackets = packet.GetSubpackets();

            foreach (SubPacket subpacket in subPackets)
            {
                //Initial Connect Packet, Create session
                if (subpacket.header.type == 0x01)
                {
                    HelloPacket hello = new HelloPacket(packet.data);

                    if (packet.header.connectionType == BasePacket.TYPE_ZONE)
                    {
                        mServer.AddSession(client, Session.Channel.ZONE, hello.sessionId);
                        Session session = mServer.GetSession(hello.sessionId);
                        session.routing1 = mServer.GetWorldManager().GetZoneServer(session.currentZoneId);
                        session.routing1.SendSessionStart(session, true);
                    }
                    else if (packet.header.connectionType == BasePacket.TYPE_CHAT)
                    {
                        mServer.AddSession(client, Session.Channel.CHAT, hello.sessionId);
                    }

                    client.QueuePacket(_0x7Packet.BuildPacket(0x0E016EE5));
                    client.QueuePacket(_0x2Packet.BuildPacket(hello.sessionId));
                }
                //Ping from World Server
                else if (subpacket.header.type == 0x07)
                {
                    SubPacket init = _0x8PingPacket.BuildPacket(client.owner.sessionId);
                    client.QueuePacket(BasePacket.CreatePacket(init, true, false));
                }
                //Zoning Related
                else if (subpacket.header.type == 0x08)
                {
                    //Response, client's current [actorID][time]
                    //BasePacket init = Login0x7ResponsePacket.BuildPacket(BitConverter.ToUInt32(packet.data, 0x10), Utils.UnixTimeStampUTC(), 0x07);
                    //client.QueuePacket(init);
                    packet.DebugPrintPacket();
                }
                //Game Message
                else if (subpacket.header.type == 0x03)
                {
                    //Send to the correct zone server
                    uint targetSession = subpacket.header.targetId;

                    InterceptProcess(mServer.GetSession(targetSession), subpacket);

                    if (mServer.GetSession(targetSession).routing1 != null)
                    {
                        mServer.GetSession(targetSession).routing1.SendPacket(subpacket);
                    }

                    if (mServer.GetSession(targetSession).routing2 != null)
                    {
                        mServer.GetSession(targetSession).routing2.SendPacket(subpacket);
                    }
                }
                //World Server Type
                else if (subpacket.header.type >= 0x1000)
                {
                    uint    targetSession = subpacket.header.targetId;
                    Session session       = mServer.GetSession(targetSession);

                    switch (subpacket.header.type)
                    {
                    //Session Begin Confirm
                    case 0x1000:
                        SessionBeginConfirmPacket beginConfirmPacket = new SessionBeginConfirmPacket(packet.data);

                        if (beginConfirmPacket.invalidPacket || beginConfirmPacket.errorCode == 0)
                        {
                            Program.Log.Error("Session {0} had a error beginning session.", beginConfirmPacket.sessionId);
                        }

                        break;

                    //Session End Confirm
                    case 0x1001:
                        SessionEndConfirmPacket endConfirmPacket = new SessionEndConfirmPacket(packet.data);

                        if (!endConfirmPacket.invalidPacket && endConfirmPacket.errorCode != 0)
                        {
                            //Check destination, if != 0, update route and start new session
                            if (endConfirmPacket.destinationZone != 0)
                            {
                                session.currentZoneId = endConfirmPacket.destinationZone;
                                session.routing1      = Server.GetServer().GetWorldManager().GetZoneServer(endConfirmPacket.destinationZone);
                                session.routing1.SendSessionStart(session);
                            }
                            else
                            {
                                mServer.RemoveSession(Session.Channel.ZONE, endConfirmPacket.sessionId);
                                mServer.RemoveSession(Session.Channel.CHAT, endConfirmPacket.sessionId);
                            }
                        }
                        else
                        {
                            Program.Log.Error("Session {0} had an error ending session.", endConfirmPacket.sessionId);
                        }

                        break;

                    //Zone Change Request
                    case 0x1002:
                        WorldRequestZoneChangePacket zoneChangePacket = new WorldRequestZoneChangePacket(packet.data);

                        if (!zoneChangePacket.invalidPacket)
                        {
                            mServer.GetWorldManager().DoZoneServerChange(session, zoneChangePacket.destinationZoneId, "", zoneChangePacket.destinationSpawnType, zoneChangePacket.destinationX, zoneChangePacket.destinationY, zoneChangePacket.destinationZ, zoneChangePacket.destinationRot);
                        }

                        break;
                    }
                }
                else
                {
                    packet.DebugPrintPacket();
                }
            }
        }