Пример #1
0
        public void HandleNewClient(ClientProxy inClientProxy)
        {
            int  playerId = inClientProxy.GetPlayerId();
            byte worldId  = inClientProxy.GetWorldId();

            GameMode.sInstance.AddEntry((uint32_t)playerId, inClientProxy.GetName());
            SpawnActorForPlayer(playerId, worldId);

            ServerMonitor.sInstance.AddUser(worldId);
        }
Пример #2
0
        public void HandleLostClient(ClientProxy inClientProxy)
        {
            //kill client's actor
            //remove client from scoreboard
            int playerId = inClientProxy.GetPlayerId();

            GameMode.sInstance.RemoveEntry((uint32_t)playerId);
            SActor actor = GetActorForPlayer(playerId, inClientProxy.GetWorldId());

            if (actor != null)
            {
                actor.Unpossess();
                actor.SetDoesWantToDie(true);
            }

            if (ServerMonitor.sInstance.DelUser(inClientProxy.GetWorldId()) == 0)
            {
                Log.Information(string.Format("Close World {0}", inClientProxy.GetWorldId()));
                NetworkManagerServer.sInstance.Clear(inClientProxy.GetWorldId());
                World.Instance(inClientProxy.GetWorldId()).Clear();
            }
        }
Пример #3
0
        void HandlePacketFromNewClient(NetIncomingMessage inInputStream, System.Net.IPEndPoint inFromAddress)
        {
            //read the beginning- is it a hello?
            uint32_t packetType = inInputStream.ReadUInt32();

            if (packetType == (uint32_t)PacketType.kHelloCC)
            {
                //read the name
                string name    = inInputStream.ReadString();
                byte   worldId = inInputStream.ReadByte();

                ClientProxy newClientProxy = new ClientProxy(inFromAddress, name, mNewPlayerId++, worldId);
                newClientProxy.mConnection         = inInputStream.SenderConnection;
                mAddressToClientMap[inFromAddress] = newClientProxy;
                mPlayerIdToClientMap[newClientProxy.GetPlayerId()] = newClientProxy;


                Log.Information(string.Format("HandlePacketFromNewClient new client {0} as player {1}, addr_map{2}, id_map{3}, world_id{4}",
                                              newClientProxy.GetName(), newClientProxy.GetPlayerId(), mAddressToClientMap.Count, mPlayerIdToClientMap.Count, newClientProxy.GetWorldId()
                                              ));


                //tell the server about this client, spawn a cat, etc...
                //if we had a generic message system, this would be a good use for it...
                //instead we'll just tell the server directly
                ((Server)Engine.sInstance).HandleNewClient(newClientProxy);

                //and welcome the client...
                SendWelcomePacket(newClientProxy);

                //and now init the replication manager with everything we know about!
                foreach (var pair in mNetworkIdToGameObjectMap)
                {
                    if (pair.Value.WorldId == newClientProxy.GetWorldId())
                    {
                        newClientProxy.GetReplicationManagerServer().ReplicateCreate(pair.Key, pair.Value.GetAllStateMask());
                    }
                }
            }
            else
            {
                //bad incoming packet from unknown client- we're under attack!!
                //LOG("Bad incoming packet from unknown client at socket %s", inFromAddress);
            }
        }