예제 #1
0
 private void Update()
 {
     while (Client.IsConnected)
     {
         lock (SendBlockQueue)
         {
             IBlockEvent blockEvent;
             if (SendBlockQueue.TryDequeue(out blockEvent))
             {
                 var serializer = BitStream.Create();
                 blockEvent.Serialize(serializer);
                 var block         = serializer.GetRawBuffer();
                 var newBlockEvent = new DataBlockEvent((uint)block.Length, (uint)blockEvent.BlockEventId); //first we send info about a new block
                 Client.SendEvent(newBlockEvent);                                                           //this doesnt send yet, it queues the event
                 foreach (var chunk in block.GetChunks(63))
                 {
                     var sendBlockEvent = new DataBlockEvent(chunk, (uint)chunk.Length);
                     Client.SendEvent(sendBlockEvent); //queue the chunks
                 }
                 Client.Send();                        //send the block data
             }
         }
         Thread.Sleep(500);
     }
 }
예제 #2
0
        public static void CreatePlayerCommand(BasePlayer sender, int playerId, string name, int skin)
        {
            var bs = BitStream.Create();

            bs.WriteValue(ParamType.UInt16, playerId, ParamType.Int32, 0, ParamType.UInt8, 0, ParamType.UInt8, name.Length, ParamType.String, name);

            int serverJoin = 137;

            bs.SendRpc(serverJoin, sender.Id);


            bs = BitStream.Create();

            int   team  = sender.Team;
            float x     = sender.Position.X;
            float y     = sender.Position.Y;
            float z     = sender.Position.Z;
            float angle = 0;
            int   color = Color.Aqua;
            int   fight = 0;

            bs.WriteValue(ParamType.UInt16, playerId, ParamType.UInt8, team, ParamType.UInt32, skin, ParamType.Float, x, ParamType.Float, y, ParamType.Float, z, ParamType.Float, angle, ParamType.UInt32, color, ParamType.UInt8, fight);

            int worldPlayerAdd = 32;

            bs.SendRpc(worldPlayerAdd, sender.Id);
            sender.SendClientMessage("Creating Player with Rpc!");
        }
예제 #3
0
        public static void SetNameCommand(BasePlayer sender, string name)
        {
            var BS = BitStream.Create();

            BS.WriteValue(ParamType.UInt16, sender.Id, ParamType.UInt8, name.Length, ParamType.String, name);

            BS.SendRpc(11, sender.Id);
            sender.SendClientMessage("Changing name with Rpc!");
        }
예제 #4
0
 public void Send()
 {
     if (ParentServer == null)
     {
         return;
     }
     if (mustSend)//only send a packet if we have data to send
     {
         lock (this)
         {
             IBitStream stream = BitStream.Create();                                //create new bitstream
             stream.WriteBasicHeader(15, ConnectionId);                             //write packet type and client id
             stream.WriteExtendedHeader(ServerPacketId, ClientPacketId, (uint)v54); //write packet identifiers
             ServerPacketId++;
             var position = stream.GetPosition();
             stream.SkipBits(16);
             stream.WriteBits(0, 1);//playeractionmanager
             if (GameEvents.Count > 0)
             {
                 stream.WriteBits(1, 1);
                 lock (GameEvents)
                 {
                     List <IGameEvent> events = new List <IGameEvent>();
                     for (int i = 4; i > 0; i--)
                     {
                         IGameEvent gameEvent;
                         if (!GameEvents.TryDequeue(out gameEvent))
                         {
                             break;
                         }
                         events.Add(gameEvent);
                     }
                     GameEventManager.Transmit(stream, events);
                 }
             }
             else
             {
                 stream.WriteBits(0, 1);
             }
             stream.WriteBits(0, 1);//ghostmanager
             var lastPosition = stream.GetPosition();
             stream.SetPosition(position);
             stream.WriteBits(((uint)(lastPosition - 72) / 8), 16);
             stream.SetPosition(lastPosition);
             ParentServer.Send(stream.GetRawBuffer(), RemoteEndPoint);
             Console.WriteLine("[NetworkingClient - " + RemoteEndPoint.ToString() + "] sent packet type " + Convert.ToString(PacketType.Data));
             mustSend = false;
         }
     }
     else
     {
         SendPingRequest();
     }
 }
예제 #5
0
        public static void SetPosCommand(BasePlayer sender, float x, float y, float z)
        {
            var BS = BitStream.Create();

            BS.WriteValue(ParamType.Float, x, ParamType.Float, y, ParamType.Float, z);

            int setPosRpc = 12;

            BS.SendRpc(setPosRpc, sender.Id);
            sender.SendClientMessage("Setting position with Rpc!");
        }
예제 #6
0
        public void UpdateAdapter(byte[] data)
        {
            _Stream = BitStream.Create(data);      // Pass bitstream controller data
            if (_Stream.ReadByte() != _Identifier) // Magic identifier check
            {
                throw new Exception(Strings.EXCEPTION_IDENTIFIER);
            }

            for (int i = 0; i < 4; i++)
            {
                Controllers[i].ReadControllerData(_Stream);
                Controllers[i].UpdateCenter();
            }
        }
예제 #7
0
        public static void ExplodeCommand(BasePlayer sender)
        {
            var   bs     = BitStream.Create();
            float x      = sender.Position.X;
            float y      = sender.Position.Y;
            float z      = sender.Position.Z;
            int   type   = 1;
            float radius = 100.0f;

            bs.WriteValue(ParamType.Float, x, ParamType.Float, y, ParamType.Float, z, ParamType.UInt16, type, ParamType.Float, radius);

            int createExplosionRpc = 79;

            bs.SendRpc(createExplosionRpc, sender.Id);
            sender.SendClientMessage("Creating Explosion with Rpc!");
        }