Ejemplo n.º 1
0
        public void SendMyMessage(string text)
        {
            MessageUpdate update = new MessageUpdate();

            update.Length = text.Length;
            peer.SendPlayerMessage(update, text);
        }
Ejemplo n.º 2
0
        public void SendPlayerMessage(MessageUpdate update, string text)
        {
            if (inSession)
            {
                NetworkPacket packet = new NetworkPacket();

                packet.Write((byte)MessageType.GameChat);
                packet.Write(update);

                packet.Write(text);

                peerObject.SendTo((int)PlayerID.AllPlayers, packet, 0, SendFlags.NoComplete | SendFlags.NoLoopback);
            }
        }
Ejemplo n.º 3
0
        public void DataReceived(object sender, ReceiveEventArgs rea)
        {
            int senderID = rea.Message.SenderID;

            byte        mType       = (byte)rea.Message.ReceiveData.Read(typeof(byte));
            MessageType messageType = (MessageType)mType;

            switch (messageType)
            {
            case MessageType.PlayerUpdateID:
            {
                PlayerUpdate update = (PlayerUpdate)rea.Message.ReceiveData.Read(typeof(PlayerUpdate));

                rea.Message.ReceiveData.Dispose();

                lock (otherPlayers)
                {
                    object playerObject = otherPlayers[senderID];
                    if (null == playerObject)
                    {
                        return;
                    }
                    RemotePlayer player = (RemotePlayer)playerObject;

                    player.Position   = update.position;
                    player.Velocity   = update.velocity;
                    player.UpdateTime = DateTime.Now;
                    player.Active     = true;

                    otherPlayers[senderID] = player;
                }

                break;
            }


            case MessageType.GameTime:
            {
                float stime = (float)rea.Message.ReceiveData.Read(typeof(float));

                rea.Message.ReceiveData.Dispose();

                serverTime = stime - DXUtil.Timer(DirectXTimer.GetApplicationTime);

                break;
            }

            case MessageType.GameChat:
            {
                MessageUpdate update = (MessageUpdate)rea.Message.ReceiveData.Read(typeof(MessageUpdate));

                string s = "";

                s += rea.Message.ReceiveData.ReadString();

                rea.Message.ReceiveData.Dispose();

                lock (otherPlayers)
                {
                    object playerObject = otherPlayers[senderID];
                    if (null == playerObject)
                    {
                        return;
                    }
                    RemotePlayer player = (RemotePlayer)playerObject;

                    mainform.textBox2.Text += player.ToString() + s + "\r\n";
                }

                break;
            }
            }
        }