Esempio n. 1
0
        public void Update()
        {
            Packet p = ServerInterface.Receive();

            while (p != null)
            {
                switch (p.data[0])
                {
                case (byte)DefaultMessageIDTypes.ID_CONNECTION_LOST:
                case (byte)DefaultMessageIDTypes.ID_DISCONNECTION_NOTIFICATION:
                {
                    if (!sWorld.GUIDToPlayer.ContainsKey(p.guid.g))
                    {
                        Log.Logger.log("Disconnected: " + ConnectionCount() + " " + p.guid);
                    }
                    else
                    {
                        Player pl = sWorld.GUIDToPlayer[p.guid.g];
                        pl.IsConnected = false;

                        foreach (NPC npc in pl.NPCControlledList)
                        {
                            npc.NpcController = null;
                        }
                        new DisconnectMessage().Write(ReceiveBitStream, this, pl);

                        sWorld.removeVob(pl);
                        if (pl.IsSpawned)
                        {
                            sWorld.getWorld(pl.Map).removeVob(pl);
                        }

                        if (p.data[0] == (byte)DefaultMessageIDTypes.ID_CONNECTION_LOST)
                        {
                            Scripting.Objects.Character.Player.isOnConnectionLost((Scripting.Objects.Character.Player)pl.ScriptingNPC);
                        }
                    }

                    break;
                }

                case (byte)DefaultMessageIDTypes.ID_NEW_INCOMING_CONNECTION:
                {
                    Log.Logger.log("New Connections: " + ConnectionCount() + " " + p.guid + " " + p.systemAddress);
                    break;
                }

                case (byte)DefaultMessageIDTypes.ID_USER_PACKET_ENUM:

                    ReceiveBitStream.Reset();
                    ReceiveBitStream.Write(p.data, p.length);
                    ReceiveBitStream.IgnoreBytes(2);
                    try
                    {
                        if (MessageListener.ContainsKey(p.data[1]))
                        {
                            MessageListener[p.data[1]].Read(ReceiveBitStream, p, this);
                        }
                    }
                    catch (Exception ex)
                    {
                        Log.Logger.log(Log.Logger.LOG_ERROR, ex.Source + " <br>" + ex.Message + "<br>" + ex.StackTrace);
                        ServerInterface.CloseConnection(p.guid, true);
                    }
                    break;

                default:
                    Log.Logger.log(Log.Logger.LOG_INFO, "Message-Type: " + ((DefaultMessageIDTypes)p.data[0]));
                    break;
                }
                ServerInterface.DeallocatePacket(p);
                p = ServerInterface.Receive();
            }
        }