Esempio n. 1
0
        void SendStatePacketToClient(ClientProxy inClientProxy)
        {
            //build state packet
            var statePacket = GetServer().CreateMessage();

            //it's state!
            statePacket.Write((uint32_t)PacketType.kStateCC);

            InFlightPacket ifp = inClientProxy.GetDeliveryNotificationManager().WriteState(statePacket);

            WriteLastMoveTimestampIfDirty(statePacket, inClientProxy);

            AddScoreBoardStateToPacket(statePacket);

            var rmtd = new ReplicationManagerTransmissionData(inClientProxy.GetReplicationManagerServer());

            inClientProxy.GetReplicationManagerServer().Write(statePacket, rmtd);
            ifp.SetTransmissionData((int)TransmissionDataType.kReplicationManager, rmtd);

            var ret = GetServer().SendMessage(statePacket, inClientProxy.mConnection, NetDeliveryMethod.Unreliable);
            //log.InfoFormat("send {0}", ret);
        }
Esempio n. 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);
            }
        }