Exemplo n.º 1
0
        //Approves the client connecting to the server
        public void ConnectionApproval(NetIncomingMessage inc)
        {
            Console.WriteLine("New Connection...");
            var packet = PacketInfo.readFromMessage(inc);

            Console.WriteLine(packet.ToString());
            Console.WriteLine(packet.getPacketType());
            if (packet.getPacketType() == Packets.ClientPacketTypes.Type_Login)
            {
                Console.WriteLine("Connection Approved");

                inc.SenderConnection.Approve();

                Player player = CreatePlayer(inc);
                //SendNewPlayer(player, inc);
                Console.WriteLine(player.Name);
                var outMessage = server.CreateMessage();
                outMessage.Write((byte)PacketType.Login);
                outMessage.Write(true);

                outMessage.Write(player.xPosition);
                outMessage.Write(player.yPosition);


                server.SendMessage(outMessage, inc.SenderConnection, NetDeliveryMethod.ReliableOrdered, 0);

                var outMessage2 = server.CreateMessage();
                outMessage2.Write((byte)PacketType.AllPlayers);
                //SendFullPlayerList(inc, outMessage2);
                SendNewPlayer(player, inc);


                Console.WriteLine("Finished Connect");
            }
            else
            {
                inc.SenderConnection.Deny("Didn't send the right data...");
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Reads the packet info from a message.
 /// </summary>
 /// <param name="msg"></param>
 /// <returns></returns>
 private PacketInfo readPacketInfo(NetIncomingMessage msg)
 {
     return(PacketInfo.readFromMessage(msg));
 }