コード例 #1
0
ファイル: Server.cs プロジェクト: devforgood/engine
        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
        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);
            }
        }
コード例 #3
0
        void HandleClientDisconnected(ClientProxy inClientProxy)
        {
            mPlayerIdToClientMap.Remove(inClientProxy.GetPlayerId());
            mAddressToClientMap.Remove(inClientProxy.GetSocketAddress());
            ((Server)(Engine.sInstance)).HandleLostClient(inClientProxy);

            Log.Information(string.Format("HandleClientDisconnected client {0} as player {1}, addr_map{2}, id_map{3}", inClientProxy.GetName(), inClientProxy.GetPlayerId(), mAddressToClientMap.Count, mPlayerIdToClientMap.Count));


            //was that the last client? if so, bye!
            if (mAddressToClientMap.Count == 0)
            {
                //Engine.sInstance.SetShouldKeepRunning(false);
            }
        }
コード例 #4
0
        void SendWelcomePacket(ClientProxy inClientProxy)
        {
            var welcomePacket = GetServer().CreateMessage();

            welcomePacket.Write((uint32_t)PacketType.kWelcomeCC);
            welcomePacket.Write(inClientProxy.GetPlayerId());

            Log.Information(string.Format("Server Welcoming, new client {0} as player {1}", inClientProxy.GetName(), inClientProxy.GetPlayerId()));

            GetServer().SendMessage(welcomePacket, inClientProxy.mConnection, NetDeliveryMethod.Unreliable);
        }