예제 #1
0
        public PackageFactory(ClientWrapper client, MsgBuffer buffer)
        {
            #region Ping

            PingPackages.Add(new Handshake(client, buffer));
            PingPackages.Add(new Ping(client, buffer));

            #endregion

            #region Play

            PlayPackages.Add(new ChatMessage(client, buffer));
            PlayPackages.Add(new KeepAlive(client, buffer));
            PlayPackages.Add(new OnGround(client, buffer));
            PlayPackages.Add(new PlayerPositionAndLook(client, buffer));
            PlayPackages.Add(new PlayerPosition(client, buffer));
            PlayPackages.Add(new PlayerLook(client, buffer));
            PlayPackages.Add(new PlayerBlockPlacement(client, buffer));
            PlayPackages.Add(new PlayerDigging(client, buffer));
            PlayPackages.Add(new HeldItemChange(client, buffer));
            PlayPackages.Add(new UseEntity(client, buffer));
            PlayPackages.Add(new CreativeInventoryAction(client, buffer));
            PlayPackages.Add(new Animation(client, buffer));
            PlayPackages.Add(new ClientStatus(client, buffer));

            #endregion

            _client = client;
            _buffer = buffer;
        }
예제 #2
0
파일: Package.cs 프로젝트: EmreTr1/MiNET-PC
 public void Broadcast(bool self = true, Player source = null)
 {
     foreach (var i in PluginGlobals.PcPlayers)
     {
         if (!self && i == source)
         {
             continue;
         }
         Client = i.Wrapper;
         Buffer = new MsgBuffer(i.Wrapper);
         Write();
     }
 }
예제 #3
0
        private void HandleClientCommNew(object client)
        {
            TcpClient tcpClient = (TcpClient)client;
            NetworkStream clientStream = tcpClient.GetStream();
            ClientWrapper Client = new ClientWrapper(tcpClient);

            while (true)
            {
                try
                {
                    MsgBuffer Buf = new MsgBuffer(Client);
                    int ReceivedData = clientStream.Read(Buf.BufferedData, 0, Buf.BufferedData.Length);
                    if (ReceivedData > 0)
                    {
                        int length = Buf.ReadVarInt();
                        Buf.Size = length;
                        int packid = Buf.ReadVarInt();
                        bool found = false;
                        if (!new PackageFactory(Client, Buf).Handle(packid)) ;
                        else found = true;

                        if (!found)
                        {
                            ConsoleFunctions.WriteWarningLine("Unknown packet received! \"0x" + packid.ToString("X2") + "\"");
                            // Client.Player.SendChat("We received an unknown packet from you! 0x" + packid.ToString("X2") + "");
                        }
                    }
                    else
                    {
                        //Stop the while loop. Client disconnected!
                        break;
                    }
                }
                catch (Exception ex)
                {
                    //Exception, disconnect!
                    ConsoleFunctions.WriteDebugLine("Error: \n" + ex);
                    new Disconnect(Client) { Reason = "§4MiNET PC\n§fServer threw an exception!\n\nFor the nerdy people: \n" + ex.Message }.Write();
                    break;
                }
            }
            //Close the connection with the client. :)
            Client.StopKeepAliveTimer();

            if (Client.Player != null)
            {
                //Globals.Level.RemovePlayer(Client.Player);
                //Globals.Level.BroadcastPlayerRemoval(Client);
            }
            Client.TCPClient.Close();
        }
예제 #4
0
파일: Package.cs 프로젝트: EmreTr1/MiNET-PC
 protected Package(ClientWrapper client, MsgBuffer buffer)
 {
     if (!client.TCPClient.Connected) return;
     Client = client;
     Buffer = buffer;
 }
예제 #5
0
파일: Package.cs 프로젝트: EmreTr1/MiNET-PC
 protected Package(ClientWrapper client)
 {
     if (!client.TCPClient.Connected) return;
     Client = client;
     Buffer = new MsgBuffer(client);
 }