示例#1
0
        private static void ProcessClientUserCommand(ServerClient client, BitStream message)
        {
            var         numCommands = message.ReadByte();
            var         commands    = new UserCommand[numCommands];
            UserCommand?lastCommand = null;

            for (int i = 0; i < numCommands; i++)
            {
                commands[i] = new UserCommand();
                commands[i].Deserialize(message, lastCommand);

                lastCommand = commands[i];
            }

            if (client.State != ServerClientState.Active && client.State != ServerClientState.Zombie)
            {
                client.InitializeEntity();
            }

            foreach (var command in commands)
            {
                client.ProcessCommand(command);
            }
        }
示例#2
0
 internal ServerClientEntityBase(ServerClient client)
 {
     _client = client;
     _bases  = new BitStream[32];
 }
示例#3
0
        private static void SendSnapshot(ServerClient client)
        {
            // send entity states
            var message = new BitStream();

            // reliable messages
            for (uint i = client.ReliableAcknowledged + 1; i <= client.ReliableSequence; i++)
            {
                // header byte
                message.WriteByte(Server.ReliableCommandNumber);

                // command number
                message.WriteUInt32(i);

                // command
                message.WriteString(client.ReliableCommands[i & (client.ReliableCommands.Length - 1)]);
            }

            message.WriteByte(Server.SnapshotNumber);
            message.WriteUInt32(_serverTime);
            message.WriteUInt32(client.LastReceivedReliableCommand);

            var useDelta = true;

            if ((client.Channel.SequenceOut - client.LastAcknowledgedMessage) >= 28)
            {
                useDelta = false;
                Log.Write(LogLevel.Warning, "client {0} lagged behind more than [max stored old packets]", client.Name);
            }

            for (int i = 0; i < Entities.Length; i++)
            {
                var entity = Entities[i];

                if (entity == null)
                {
                    continue;
                }

                // write the entity number
                message.WriteInt32(i, 12);

                var entityBase = (useDelta) ? ((client.EntityBases[i] != null) ? client.EntityBases[i].Get() : null) : null;

                var deltaMessage = new DeltaBitStream(entityBase, message);

                // write the spawn key
                deltaMessage.WriteInt32(entity.SpawnKey, 20);

                // write the type code
                deltaMessage.WriteInt32(entity.TypeCode, 4);

                // write the actual data
                entity.Serialize(deltaMessage);

                // set the new base
                if (client.EntityBases[i] == null)
                {
                    client.EntityBases[i] = new ServerClientEntityBase(client);
                }

                client.EntityBases[i].Set(deltaMessage.NewBase);
            }

            message.WriteInt32(4095, 12);
            message.WriteByte(0xFF);

            // send the message
            client.Channel.SendMessage(message);
        }