Esempio n. 1
0
 ///<summary>
 /// Write a Player Primitive (just data, no graphics) to outgoing server message
 ///</summary>
 public static void Write(this NetOutgoingMessage message, PlayerPrimitive playerPrim)
 {
     message.Write(playerPrim.Name);
     //XNAExtensions.Write(message, playerPrim.Position);
     message.Write(playerPrim.X);
     message.Write(playerPrim.Y);
     message.Write(playerPrim.UniqueId);
 }
Esempio n. 2
0
 ///<summary>
 /// Read a Player Primitive
 ///</summary>
 public static PlayerPrimitive ReadPlayer(this NetIncomingMessage message)
 {
     PlayerPrimitive playerPrim = new PlayerPrimitive();
     playerPrim.Name = message.ReadString();
     //playerPrim.Position = XNAExtensions.ReadVector2(message);
     playerPrim.X = message.ReadInt32();
     playerPrim.Y = message.ReadInt32();
     playerPrim.UniqueId = message.ReadInt32();
     return playerPrim;
 }
Esempio n. 3
0
        public void Start(Player player)
        {
            NetOutgoingMessage outmsg = mClient.CreateMessage();

            mClient.Start();

            PlayerPrimitive playerPrim = new PlayerPrimitive();
            mClientsId = playerPrim.UniqueId;

            playerPrim.X = (int)player.Coordinates.X;
            playerPrim.Y = (int)player.Coordinates.Y;
            playerPrim.Name = "Quas";

            outmsg.Write((byte)PacketTypes.Login);
            DataReadWrite.Write(outmsg, playerPrim);

            mClient.Connect(mHostIP, 7377, outmsg);

            Console.WriteLine("Client started");
            Console.WriteLine("epic");

            mPlayerList = new Dictionary<int, PlayerPrimitive>();

            mUpdater = new System.Timers.Timer(50);
            mUpdater.Elapsed += new System.Timers.ElapsedEventHandler(UpdateElapsed);
            mUpdater.Enabled = true;

            WaitForStartingInfo();
        }
Esempio n. 4
0
        private void UpdatePlayerList(NetIncomingMessage nim)
        {
            lock (mPlayerList)
            {
                mPlayerList.Clear();

                int playerCount = 0;
                playerCount = nim.ReadInt32();

                int npcCount = 0;
                npcCount = nim.ReadInt32();

                for (int i = 0; i < playerCount; i++)
                {
                    PlayerPrimitive player = new PlayerPrimitive();
                    nim.ReadAllProperties(player);
                    if(player.UniqueId != ClientsUniqueId)
                        Console.WriteLine("player: " + player.Name + " x: " + player.X + "; y: " + player.Y);

                    mPlayerList.Add(player.UniqueId, player);
                }

                for (int i = 0; i < npcCount; i++)
                {
                    PlayerPrimitive player = new PlayerPrimitive();
                    nim.ReadAllProperties(player);
                    if (player.UniqueId != ClientsUniqueId)
                        Console.WriteLine("player: " + player.Name + " x: " + player.X + "; y: " + player.Y);

                    mPlayerList.Add(player.UniqueId, player);
                }
            }
        }