internal void HandlePacket(Packet P)
 {
     string[] data = P.Data.ToArray();
     switch (data[0])
     {
         case "_update":
             {
                 Update(data);
             }return;
         default:
             {
                 Console.WriteLine("OMG I CAN HAZ PACKETZ! {0}, {1}", P.Data.ToArray());
             }return;
     }
 }
        public void Thread()
        {
            #if DEBUG
            Accounts = new List<AccountData>(new[] { new AccountData("Test", SkyNet.MD5.HashString("Monkey")) });
            #endif
            NetIncomingMessage msg;
            string header;
            while (!_running) ;
            while (_running)
            {
                try
                {
                    if ((msg = _server.ReadMessage()) == null)
                        continue;
                    switch (msg.MessageType)
                    {
                        case NetIncomingMessageType.StatusChanged:
                            {
                                NetConnectionStatus status = (NetConnectionStatus)msg.ReadByte();
                                string reason = msg.ReadString();
                                if (status == NetConnectionStatus.Connected)
                                {
                                    var a = from player in ActivePlayers
                                            where player._connection == msg.SenderConnection
                                            select player;
                                    if (a.Count() != 0)
                                    {
                                        msg.SenderConnection.Deny("Already Active");
                                        break;
                                    }
                                    PlayerData data = new PlayerData()
                                    {
                                        _connection = msg.SenderConnection
                                    };
                                    ActivePlayers.Add(data);
                                }
                            }break;
                        case NetIncomingMessageType.Data:
                            {
                                var a = from player in ActivePlayers
                                        where player._connection == msg.SenderConnection
                                        select player;
                                if(a.Count()!=1)
                                    break;
                                header = msg.ReadString();
                                switch (header)
                                {
                                    case "__msg":
                                        {
                                            Packet p = Packet.FromIncoming(msg);
                                            switch (p.Header)
                                            {
                                                case HeaderValue.Login:
                                                    {
                                                        string name =
                                                            p.Data[0],
                                                            pass = p.Data[1];
                                                        var accs = from Acc in Accounts
                                                                   where Acc._name == name
                                                                   select Acc;
                                                        p = new Packet(HeaderValue.Login_Reply, _server.UniqueIdentifier.ToString(), new[] { accs.Count() == 0 ? "1" : (accs.First().Login(pass).ToString()) });
                                                        msg.SenderConnection.SendMessage(p.ToOutgoing(_server), NetDeliveryMethod.ReliableOrdered, 0);
                                                    }break;
                                                default:
                                                    a.First().PacketReceived(p); break;
                                            }
                                        } break;
                                    case "__cht":
                                        {

                                        }break;
                                }
                            }break;
                    }
                }
                catch (System.Exception ex)
                {

                }
            }
        }
 public void SendPacket(Packet P)
 {
     _client.Connections[0].SendMessage(P.ToOutgoing(_client), NetDeliveryMethod.ReliableOrdered, 0);
 }
 public void SendPacket(Packet P, NetConnection Connection)
 {
     Connection.SendMessage(P.ToOutgoing(_client), NetDeliveryMethod.ReliableOrdered, 0);
 }
 internal virtual void ReceivePacket(Packet P)
 {
     PacketReceived(P);
 }