Exemplo n.º 1
0
        public void Tick()
        {
            if (NetworkService.IsAvalible(new Ping()))
            {
                var p = NetworkService.GetPacket <Ping>() as Ping;
                NetworkService.EnqueuePacket(new Pong()
                {
                    Owner = p.Owner, Payload = p.Payload, Send = true, KillSwitch = true
                });
            }

            if (NetworkService.IsAvalible(new Request()))
            {
                var p    = NetworkService.GetPacket <Request>() as Request;
                var resp = new Response()
                {
                    Owner = p.Owner
                };
                resp.Json = JsonConvert.SerializeObject(new SResponce(), Formatting.Indented);
                NetworkService.EnqueuePacket(resp);
            }

            if (NetworkService.IsAvalible(new HandShake()))
            {
                var p = NetworkService.GetPacket <HandShake>() as HandShake;
                foreach (var i in NetworkService._cw)
                {
                    if (i.OwnerID == p.Owner)
                    {
                        i.State = p.NextState;
                        break;
                    }
                }
            }
        }
Exemplo n.º 2
0
        public void Tick()
        {
            lock (MinecraftServer.Worlds)
            {
                foreach (var i in MinecraftServer.Worlds)
                {
                    foreach (var p in i.Players)
                    {
                        var ka = new KeepAlive()
                        {
                            Owner = p.OwnerID
                        };
                        ka.KeepAliveID = new Random().Next();

                        NetworkService.EnqueuePacket(ka);
                    }
                }
            }

            if (NetworkService.IsAvalible(new LoginStart()))
            {
                var p  = NetworkService.GetPacket <LoginStart>() as LoginStart;
                var pl = new Player()
                {
                    OwnerID = p.Owner, Name = p.Name
                };


                var Logins = new LoginSuccess()
                {
                    Owner = p.Owner
                };
                Logins.Username = p.Name;
                Logins.UUID     = GetUuid(p.Name);

                NetworkService.EnqueuePacket(Logins);

                var jg = new JoinGame()
                {
                    Owner = p.Owner
                };
                jg.EntityID         = 0;
                jg.Gamemode         = (byte)pl.GameMode;
                jg.Dimension        = 0;
                jg.Difficulty       = 0;
                jg.MaxPlayers       = 255;
                jg.LevelType        = "default";
                jg.ReducedDebugInfo = 0;

                NetworkService.EnqueuePacket(jg);


                var ppal = new PlayerPositionAndLook()
                {
                    Owner = p.Owner
                };
                ppal.X     = pl.Posistion.X;
                ppal.Y     = pl.Posistion.Y;
                ppal.Z     = pl.Posistion.Z;
                ppal.Yaw   = pl.Look.Yaw;
                ppal.Pitch = pl.Look.Pitch;
                ppal.Flags = 255;

                NetworkService.EnqueuePacket(ppal);

                pl.Spawned = true;

                MinecraftServer.Worlds[0].Players.Add(pl);
            }
        }