Esempio n. 1
0
        /// <summary>
        /// Handler the server registers to react to network messages
        /// </summary>
        void ServerOnDataHandler(object source, NetworkEventArgs n)
        {
            NetIncomingMessage msg     = n.GetData();
            NetworkMessageType msgType = n.GetInfo();

            if (msgType == NetworkMessageType.LoadFinish)
            {
                //just ignore the message content for now
                _loadedClients++;
                if (_loadedClients == _targetClientCount)
                {
                    OnAllLoaded();
                }
            }
            else if (msgType == NetworkMessageType.TankControl)
            {
                //read from old message
                int           networkId     = msg.ReadInt32(32);
                NetworkAction networkAction = (NetworkAction)msg.ReadByte();

                //write to new message
                NetOutgoingMessage relayMessage = Server.CreateMessage(n.GetData().LengthBits);
                relayMessage.Write((byte)NetworkMessageType.TankControl);
                relayMessage.Write(networkId, 32);
                relayMessage.Write((byte)networkAction);
                Server.SendToAll(relayMessage, NetDeliveryMethod.ReliableUnordered);
            }
        }
Esempio n. 2
0
 protected NetworkMessage(NetworkMessageType messageType, int playerIndex, long currentFrame, T data)
 {
     this.MessageType  = messageType;
     this.PlayerIndex  = playerIndex;
     this.CurrentFrame = currentFrame;
     this.Data         = data;
 }
Esempio n. 3
0
        public static byte[] CreateMovementMessage(NetworkMessageType type, float amount)
        {
            string json = JsonConvert.SerializeObject(new { Amount = amount });

            byte[] clientMessageAsByteArray = Encoding.ASCII.GetBytes(json);
            return(AddTypeAndLengthToArray(clientMessageAsByteArray, (byte)type));
        }
Esempio n. 4
0
 public static byte[] CreateZeroPayloadMessage(NetworkMessageType type)
 {
     byte[] message = new byte[2];
     message[0] = (byte)type;
     message[1] = 0;
     return(message);
 }
Esempio n. 5
0
        public static NetworkMessage Create(NetworkMessageType type, byte[] body)
        {
            switch (type)
            {
            case NetworkMessageType.Ping:
                return(new NetworkPing());

            case NetworkMessageType.DeviceName:
                return(new NetworkDeviceName(body));

            case NetworkMessageType.Text:
                return(new NetworkText(body));

            case NetworkMessageType.RemoteProcedureCall:
                return(new NetworkRemoteProcedureCall(body));

            case NetworkMessageType.RemoteFileRequest:
                return(new NetworkRemoteFileRequest(body));

            case NetworkMessageType.RemoteFile:
                return(new NetworkRemoteFile(body));

            default:
                throw new NotSupportedException();
            }
        }
Esempio n. 6
0
 /// <summary>
 /// When the server receives a message from a client, it needs to notify other clients. This is called in
 /// all of the Create, Destroy and Update methods but only performs actual logic if running as server.
 /// </summary>
 /// <param name="entityId">The ID of the affected entity.</param>
 /// <param name="ownerId">The owner of the affected entity</param>
 /// <param name="payload">The payload from the original message.</param>
 /// <param name="action">Type type of message, determining the action to be taken.</param>
 private void BroadcastIfServer(long entityId, long ownerId, object payload, NetworkMessageType action)
 {
     if (Role == NetworkRole.Server)
     {
         SendDataMessage(entityId, ownerId, payload, action);
     }
 }
Esempio n. 7
0
        private void FinalizeEncoding()
        {
            this.networkStream.Write((int)NetworkMessageType.DataEnd);

            byte[] receiveBuffer = new byte[65536];
            while (true)
            {
                NetworkMessageType messageType = (NetworkMessageType)this.networkStream.ReadInt32();
                if (messageType == NetworkMessageType.DataMessage)
                {
                    int length = this.networkStream.ReadInt32();
                    while (length > 0)
                    {
                        int read = Math.Min(receiveBuffer.Length, length);
                        this.networkStream.ReadBytes(receiveBuffer, 0, read);
                        this.outputStream.Write(receiveBuffer, 0, read);

                        length -= read;
                    }
                }
                else if (messageType == NetworkMessageType.DataEnd)
                {
                    break;
                }
            }
        }
Esempio n. 8
0
 public void Setup(int length, NetworkMessageType sendType)
 {
     this.networkMessage = NetworkMessage.Create(-4, length, sendType);
     //Number of chunks needed
     receivePartsLength = (length + 4) / 500;
     if ((length + 4) % 500 > 0)
     {
         receivePartsLength++;
     }
     //Check the send array can fit the chunks
     if (receiveParts == null || receiveParts.Length < receivePartsLength)
     {
         int createLength = 128;
         while (receivePartsLength > createLength)
         {
             createLength = createLength * 4;
         }
         receiveParts = new bool[createLength];
     }
     receivePartsLeft = receivePartsLength;
     for (int i = 0; i < receivePartsLength; i++)
     {
         receiveParts[i] = false;
     }
 }
Esempio n. 9
0
 public PayloadUpdateAlarm(List <string> description, string serial, string updateAt, NetworkMessageType type)
 {
     this.Serial      = serial;
     this.Description = description;
     this.UpdateAt    = updateAt;
     this.Type        = type;
 }
Esempio n. 10
0
 public override void DoUpdate()
 {
     //-------------------------------------------------------------------------------------------------------------
     // After that, process network messages received during the last frame
     //-------------------------------------------------------------------------------------------------------------
     foreach (byte[] serializedMessage in this.receivedMessages)
     {
         if (serializedMessage != null && serializedMessage.Length > 0)
         {
             NetworkMessageType messageType = (NetworkMessageType)serializedMessage[0];
             if (messageType == NetworkMessageType.InputBuffer)
             {
                 this.ProcessInputBufferMessage(new InputBufferMessage(serializedMessage));
             }
             else if (messageType == NetworkMessageType.RandomSeedSynchronization)
             {
                 this.ProcessRandomSeedSynchronizationMessage(new RandomSeedSynchronizationMessage(serializedMessage));
             }
             else if (messageType == NetworkMessageType.RandomSeedSynchronized)
             {
                 this.ProcessRandomSeedSynchronizedMessage(new RandomSeedSynchronizedMessage(serializedMessage));
             }
             else if (messageType == NetworkMessageType.Syncronization)
             {
                 this.ProcessSynchronizationMessage(new SynchronizationMessage(serializedMessage));
             }
         }
     }
     this.receivedMessages.Clear();
 }
Esempio n. 11
0
        public static byte[] CreateMessage(NetworkMessageType type, string token)
        {
            string message = token;

            byte[] clientMessageAsByteArray = Encoding.ASCII.GetBytes(message);
            return(AddByteStartOfToArray(clientMessageAsByteArray, (byte)type));
        }
        public NetworkMessage Create(NetworkMessageType type)
        {
            if (constructors[(int)type] == null)
                return null;

            return constructors[(int)type]();
        }
Esempio n. 13
0
        // this is a little hacky as there aren't actually any entities to process
        // probably a sign that I'm abusing the entity component system. i think the proper
        // way to do this is to create a simple entity that just has a component to hold
        // a reference to the network agent. that's roughly how it would work in unity.
        // might be best to use a TagSystem like for player input?
        protected override void ProcessEntities(IDictionary <int, Entity> entities)
        {
            List <NetIncomingMessage> messages = _networkAgent.ReadMessages();

            foreach (NetIncomingMessage netMessage in messages)
            {
                NetworkMessageType messageType = (NetworkMessageType)Enum.ToObject(typeof(NetworkMessageType), netMessage.ReadByte());

                if (messageType == NetworkMessageType.PlayerConnect)
                {
                    PlayerConnectMessage <UmbraEntityType> playerConnectMessage = new PlayerConnectMessage <UmbraEntityType>();
                    playerConnectMessage.Decode(netMessage);
                    PlayerConnect(playerConnectMessage);
                }
                else if (messageType == NetworkMessageType.EntityAdd)
                {
                    EntityAddMessage <UmbraEntityType> addMessage = new EntityAddMessage <UmbraEntityType>();
                    addMessage.Decode(netMessage);
                    AddEntity(addMessage);
                }
                else if (messageType == NetworkMessageType.EntityMove)
                {
                    EntityMoveMessage moveMessage = new EntityMoveMessage();
                    moveMessage.Decode(netMessage);
                    MoveEntity(moveMessage);
                }
                else if (messageType == NetworkMessageType.EntityRemove)
                {
                    EntityRemoveMessage removeMessage = new EntityRemoveMessage();
                    removeMessage.Decode(netMessage);
                    RemoveEntity(removeMessage);
                }
            }
        }
Esempio n. 14
0
 /// <summary>
 /// When the server receives a message from a client, it needs to notify other clients. This is called in
 /// all of the Create, Destroy and Update methods but only performs actual logic if running as server.
 /// </summary>
 /// <param name="entityId">The ID of the affected entity.</param>
 /// <param name="ownerId">The owner of the affected entity</param>
 /// <param name="payload">The payload from the original message.</param>
 /// <param name="action">Type type of message, determining the action to be taken.</param>
 private void BroadcastIfServer(ulong id, object payload, NetworkMessageType action)
 {
     if (Role == NetworkRole.Server)
     {
         SendDataMessage(id, payload, action);
     }
 }
Esempio n. 15
0
        /// <summary>
        /// Helper function to control pause for each client
        /// </summary>
        private void SendPauseCommand(NetworkMessageType networkMessageType, NetworkPauseControl data)
        {
            NetOutgoingMessage message = Server.CreateMessage();

            message.Write((byte)networkMessageType);
            message.Write((byte)data);
            Server.SendToAll(message, NetDeliveryMethod.ReliableUnordered);
        }
Esempio n. 16
0
        public static void SendMessage(NetPeer peer, NetworkMessageType networkMessageType, int data, NetConnection recipient)
        {
            NetOutgoingMessage message = peer.CreateMessage();

            message.Write((byte)networkMessageType);
            message.Write(data, 32);
            peer.SendMessage(message, recipient, NetDeliveryMethod.ReliableUnordered);
        }
Esempio n. 17
0
 public NetworkMessage(NetworkMessageType type, string senderId, string receiverId = "", string message = "")
 {
     this.Type       = type;
     this.SenderId   = senderId;
     this.ReceiverId = receiverId;
     this.Message    = message;
     this.TimeStamp  = DateTime.Now.ToString();
 }
Esempio n. 18
0
    public NetworkMessage(NetworkMessageType type)
    {
        stream = new MemoryStream();
        writer = new BinaryWriter(stream);

        MessageType = type;
        writer.Write((byte)MessageType);
    }
Esempio n. 19
0
        private void SendMessage(NetworkMessageType messageType, byte[] data, SendDataOptions options, NetworkGamer gamer)
        {
            NetOutgoingMessage message = ((NetPeer)this.peer).CreateMessage();

            message.Write((byte)messageType);
            message.Write(data);
            this.SendMessage(message, options, gamer);
        }
Esempio n. 20
0
        /// <summary>
        /// Helper to send data to all clients
        /// </summary>
        private void SendToAll(NetworkMessageType networkMessageType, int data)
        {
            NetOutgoingMessage message = Server.CreateMessage();

            message.Write((int)networkMessageType, 16);
            message.Write(data, 32);
            Server.SendToAll(message, NetDeliveryMethod.ReliableUnordered);
        }
Esempio n. 21
0
 public NetworkPingEventArgs(NetworkMessageType type, IPEndPoint source, HardwareType hw, string hostname, TimeSpan uptime, float cpu, int dbm, uint net_recv) : base(type, source)
 {
     HostName     = hostname;
     HardwareType = hw;
     Uptime       = uptime;
     CPU          = cpu;
     dBm          = dbm;
     NetRecv      = net_recv;
 }
Esempio n. 22
0
        public NetworkMessage Create(NetworkMessageType type)
        {
            if (constructors[(int)type] == null)
            {
                return(null);
            }

            return(constructors[(int)type]());
        }
        protected INetworkMessageOut CreateMessage(NetworkMessageType type)
        {
            if (NetworkImplementation == null)
            {
                throw new NullReferenceException("NetworkImplementation was not initialized.");
            }

            return(NetworkImplementation.CreateMessage(type));
        }
Esempio n. 24
0
 public NetworkMessage(string senderIP, NetworkMessageType type, string senderId, DateTime timestamp, string receiverId = "", string message = "")
 {
     this.SenderIP   = senderIP;
     this.Type       = type;
     this.SenderId   = senderId;
     this.ReceiverId = receiverId;
     this.Message    = message;
     this.TimeStamp  = timestamp.ToString();
 }
Esempio n. 25
0
        private void SendMessage(NetworkMessageType messageType, byte[] data, SendDataOptions options, NetworkGamer gamer)
        {
            NetOutgoingMessage om = peer.CreateMessage();

            om.Write((byte)messageType);
            om.Write(data);

            SendMessage(om, options, gamer);
        }
Esempio n. 26
0
        public void Update()
        {
            if (client == null)
            {
                throw new Exception("net client object is null");
            }

            NetIncomingMessage msg = null;

            while ((msg = client.ReadMessage()) != null)
            {
                switch (msg.MessageType)
                {
                case NetIncomingMessageType.StatusChanged:
                {
                    NetConnectionStatus status = (NetConnectionStatus)msg.ReadByte();

                    if (clientDelegate != null)
                    {
                        if (status == NetConnectionStatus.Connected)
                        {
                            clientDelegate.OnNetworkClientConnect(this, 1);
                        }

                        if (status == NetConnectionStatus.Disconnected)
                        {
                            clientDelegate.OnNetworkClientDisconnect(this, 1);
                        }
                    }
                }
                break;

                case NetIncomingMessageType.Data:
                {
                    NetworkMessageType msgid = (NetworkMessageType)msg.PeekUInt16();
                    NetworkMessage     flmsg = msgFactory.Create(msgid);

                    if ((clientDelegate != null) && (flmsg != null))
                    {
                        flmsg.Read(msg);
                        clientDelegate.OnNetworkClientMessage(this, flmsg);
                    }
                }
                break;

                case NetIncomingMessageType.VerboseDebugMessage:
                case NetIncomingMessageType.DebugMessage:
                case NetIncomingMessageType.WarningMessage:
                case NetIncomingMessageType.ErrorMessage:
                default:
                    break;
                }

                client.Recycle(msg);
            }
        }
Esempio n. 27
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CoCoL.Network.PendingNetworkRequest"/> class for representing a locally created request.
 /// </summary>
 /// <param name="channelid">The channel to communicate over.</param>
 /// <param name="channeldatatype">The datatype on the channel.</param>
 /// <param name="type">The message type.</param>
 /// <param name="value">The data value, if any.</param>
 public PendingNetworkRequest(string channelid, Type channeldatatype, NetworkMessageType type, object value)
 {
     ChannelID       = channelid;
     ChannelDataType = channeldatatype;
     RequestID       = Guid.NewGuid().ToString("N");
     SourceID        = NetworkConfig.SelfID;
     RequestType     = type;
     Value           = value;
     NoOffer         = true;
 }
Esempio n. 28
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CoCoL.Network.PendingNetworkRequest"/> class for representing an incoming request.
 /// </summary>
 /// <param name="channelid">The channel to communicate over.</param>
 /// <param name="channeldatatype">The datatype on the channel.</param>
 /// <param name="requestid">The request ID.</param>
 /// <param name="sourceid">The source ID.</param>
 /// <param name="timeout">The request timeout</param>
 /// <param name="type">The message type.</param>
 /// <param name="value">The data in the message, if any.</param>
 /// <param name="nooffer">If set to <c>true</c> the remote end does not have a two-phase instance associated.</param>
 public PendingNetworkRequest(string channelid, Type channeldatatype, string requestid, string sourceid, DateTime timeout, NetworkMessageType type, object value, bool nooffer)
 {
     ChannelID       = channelid;
     RequestID       = requestid;
     SourceID        = sourceid;
     Timeout         = timeout;
     ChannelDataType = channeldatatype;
     RequestType     = type;
     Value           = value;
     NoOffer         = nooffer;
 }
Esempio n. 29
0
 public static Offset <NetworkMessage> CreateNetworkMessage(FlatBufferBuilder builder,
                                                            uint id = 0,
                                                            NetworkMessageType msg_type = NetworkMessageType.NONE,
                                                            int msgOffset = 0)
 {
     builder.StartObject(3);
     NetworkMessage.AddMsg(builder, msgOffset);
     NetworkMessage.AddId(builder, id);
     NetworkMessage.AddMsgType(builder, msg_type);
     return(NetworkMessage.EndNetworkMessage(builder));
 }
        public void SendToAllClients(byte[] data, NetworkMessageType networkMessageType, SendType sendType)
        {
            if (client != null && client.IsValid)
            {
                ulong[] lobbyMemberIDs = client.Lobby.GetMemberIDs();

                foreach (ulong steamID in lobbyMemberIDs)
                {
                    SendToClient(steamID, data, (int)networkMessageType, sendType);
                }
            }
        }
Esempio n. 31
0
        /// <summary>
        /// Uses the provided entity to compose a data message.
        /// ReliableSequenced method is suggested to balance performance with deliverability.
        /// </summary>
        /// <param name="entity">The entity to build a message from.</param>
        /// <param name="action">The type of message to send.</param>
        /// <param name="method">Delivery method.</param>
        /// <param name="recipient">The recipient connection. Will send to all if null.</param>
        private void SendDataMessage(INetworkEntity entity, NetworkMessageType action, NetConnection recipient = null)
        {
            // clients can't force a message for an entity they don't own
            if (Role != NetworkRole.Server && entity.OwnerId != NetworkId)
            {
                throw new RedGrinException("Cannot send an update for an entity that is not owned by this client!");
            }

            object payload = entity.GetState();

            SendDataMessage(entity.EntityId, entity.OwnerId, payload, action, recipient);
        }
        public NetMsgDelegate this[NetworkMessageType id]
        {
            get
            {
                return handlers[(int)id];
            }

            set
            {
                handlers[(int)id] = value;
            }
        }
Esempio n. 33
0
 private void SendMessage(NetworkMessageType messageType, byte[] data, SendDataOptions options, NetworkGamer gamer)
 {
   NetOutgoingMessage message = ((NetPeer) this.peer).CreateMessage();
   message.Write((byte) messageType);
   message.Write(data);
   this.SendMessage(message, options, gamer);
 }
Esempio n. 34
0
 public static void SendMessage(NetPeer peer, NetworkMessageType networkMessageType, int data, int recipient)
 {
     SendMessage(peer, networkMessageType, data, peer.Connections[recipient]);
 }
Esempio n. 35
0
        private void sendRawData(NetworkMessageType nmt, MemoryStream memStream, object obj)
        {
            binaryFormatter.Serialize(memStream, obj);

            byte[] byteDescriptor = getByteDescriptorFromStream(memStream, nmt);

            // Send the message descriptor
            this.SendAsync(byteDescriptor, byteDescriptor.Length);

            // Send the data
            byte[] data = memStream.ToArray();
            this.SendAsync(data, data.Length);
        }
Esempio n. 36
0
 //
 // Handlers for sending network messages
 //
 private void sendRawData(NetworkMessageType nmt, object obj)
 {
     MemoryStream memStream = new MemoryStream();
     sendRawData(nmt, memStream, obj);
 }
Esempio n. 37
0
        private void receiveAsyncProcessing()
        {
            isReceiving = true;

            if (rcvdMode == receivingMode.descriptorReceived)
            {
                int messageLength = BitConverter.ToInt32(rcvdByteBuffer, 0);
                rcvdNetworkMessageType = (NetworkMessageType)BitConverter.ToInt32(rcvdByteBuffer, 4);

                resetRcvdVariables();
                receiveMessage(messageLength);
            }
            else if (rcvdMode == receivingMode.messageReceived)
            {
                byte[] data = new byte[rcvdBufferLength];
                Buffer.BlockCopy(rcvdByteBuffer, 0, data, 0, rcvdBufferLength);
                rcvdBuffer.Enqueue(new Pair<NetworkMessageType, byte[]>(rcvdNetworkMessageType, data));

                receivedMessageHandle.Set();

                resetRcvdVariables();
                rcvdMode = receivingMode.none;
            }

            if (rcvdMode == receivingMode.none)
            {
                resetRcvdVariables();
                receiveDescriptor();
            }
        }
Esempio n. 38
0
 public static void SendMessage(NetPeer peer, NetworkMessageType networkMessageType, int data, NetConnection recipient)
 {
     NetOutgoingMessage message = peer.CreateMessage();
     message.Write((byte)networkMessageType);
     message.Write(data, 32);
     peer.SendMessage(message, recipient, NetDeliveryMethod.ReliableUnordered);
 }
Esempio n. 39
0
 public virtual NetworkMessage Read(NetIncomingMessage msgIn)
 {
     type = (NetworkMessageType)msgIn.ReadUInt16();
     return this;
 }
Esempio n. 40
0
 public NetworkMessage(Guid senderID, Guid destinationID, Guid messageID, NetworkMessageType type, byte[] data, int fragment, int fragments, int life)
 {
     this.senderID = senderID;
      this.destinationID = destinationID;
      this.type = type;
      this.messageID = messageID;
      this.fragmentNumber = fragment;
      this.fragmentTotal = fragments;
      this.lifetime = life;
      if (this.FragmentTotal == 1)
      {
     // Compress the data in a memory stream
     using (MemoryStream ms = new MemoryStream())
     {
        using (GZipStream gzStream = new GZipStream(ms, CompressionMode.Compress, true))
        {
           gzStream.Write(data, 0, data.Length);
           gzStream.Flush();
           gzStream.Close();
           this.gzData = ms.ToArray();
        }
     }
      }
      else
      {
     this.gzData = new byte[data.Length];
     Array.Copy(data, this.gzData, data.Length);
      }
 }
Esempio n. 41
0
        public void Terminate(bool disconnectionAlreadyBegun, NetworkMessageType nmt, object data)
        {
            if (networkConnection != null && networkConnection.IsInitialized && isTerminated == false)
            {
                isTerminated = true;

                try
                {
                    bool isWorking = true;
                    bool received = false;
                    int state = disconnectionAlreadyBegun ? 2 : 0;
                    MessageBoxShow("Initiating disconnection of opponent..");
                    Stopwatch stopWatch = new Stopwatch();
                    stopWatch.Start();

                    int attempts = 0;

                    while (isWorking && attempts < 4 && stopWatch.ElapsedMilliseconds < 10000)
                    {
                        if (state == 1)
                        {
                            networkConnection.ReceiveAsync();
                            received = networkConnection.ReceivedMessageHandle.WaitOne(3000);

                            if (received)
                            {
                                nmt = networkConnection.GetReceivedMessageType();
                                data = networkConnection.GetReceivedMessageFromQueue();
                            }
                            /*else
                            {
                                this.AppendMessage("No message received.");
                            }*/

                            state = (received) ? 2 : 1;
                        }

                        if (state == 0)
                        {
                            networkConnection.SendAsync(NetworkMessageType.DisconnectRequest, new DisconnectRequest(DateTime.Now));
                            AppendMessage("Sending disconnection request..");
                            state = 1;
                        }
                        else if (state == 2)
                        {
                            if (nmt == NetworkMessageType.DisconnectRequest)
                            {
                                this.AppendMessage("Answering disconnect request..");
                                networkConnection.SendAsync(NetworkMessageType.DisconnectRequestConfirmation,
                                    new DisconnectRequestConfirmation(DateTime.Now));
                                networkConnection.AllSentHandle.WaitOne(3000);
                                isWorking = false;
                            }
                            else if (nmt == NetworkMessageType.DisconnectRequestConfirmation)
                            {
                                this.AppendMessage("Disconnect request confirmed");
                                isWorking = false;
                            }
                            else if (nmt != NetworkMessageType.None)
                            {
                                attempts--; // add for SimulationEvent message and so on
                            }
                        }

                        state = 1;
                        received = false;
                        attempts++;
                    }

                    this.AppendMessage("Closing connection..");
                    networkConnection.CloseConnection();
                }
                catch (SocketException e)
                {
                    DebuggerIX.WriteLine(DebuggerTag.Net, "Terminate", "Disconnection failed. SocketException: " + e.Message);
                    this.AppendMessage("Connection closed with error message: " + e.Message);
                }

                this.AppendMessage("Connection closed.");
            }
        }
Esempio n. 42
0
 /// <summary>
 /// Helper to send data to all clients
 /// </summary>
 private void SendToAll(NetworkMessageType networkMessageType, int data)
 {
     NetOutgoingMessage message = Server.CreateMessage();
     message.Write((int)networkMessageType, 16);
     message.Write(data, 32);
     Server.SendToAll(message, NetDeliveryMethod.ReliableUnordered);
 }
Esempio n. 43
0
 /// <summary>
 /// Helper function to control pause for each client
 /// </summary>
 private void SendPauseCommand(NetworkMessageType networkMessageType, NetworkPauseControl data)
 {
     NetOutgoingMessage message = Server.CreateMessage();
     message.Write((byte)networkMessageType);
     message.Write((byte)data);
     Server.SendToAll(message, NetDeliveryMethod.ReliableUnordered);
 }
Esempio n. 44
0
 public EntityMessage(long entityId, NetworkMessageType messageType)
 {
     EntityId = entityId;
     _messageType = messageType;
 }
Esempio n. 45
0
 public NetworkMessage(byte[] bytes)
 {
     using (BinaryReader reader = new BinaryReader(new MemoryStream(bytes, 0, headerSize)))
      {
     this.senderID = new Guid(reader.ReadBytes(16));
     this.destinationID = new Guid(reader.ReadBytes(16));
     this.messageID = new Guid(reader.ReadBytes(16));
     this.fragmentNumber = reader.ReadInt32();
     this.fragmentTotal = reader.ReadInt32();
     this.lifetime = reader.ReadInt32();
     this.type = (NetworkMessageType)reader.ReadInt32();
      }
      int dataLength = bytes.Length - headerSize;
      gzData = new byte[dataLength];
      Array.Copy(bytes, headerSize, gzData, 0, dataLength);
 }
Esempio n. 46
0
 /// <summary>
 /// Customer main function
 /// </summary>
 /// <param name="nmt"></param>
 public void SendAsync(NetworkMessageType nmt)
 {
     SendAsync(nmt, null);
 }
Esempio n. 47
0
        public void SendAsync(NetworkMessageType nmt, object data)
        {
            if (nmt == NetworkMessageType.ListOfEvents)
            {
                if (outBuffer.Count > 0)
                {
                    this.sendRawData(NetworkMessageType.ListOfEvents, new ListOfEventsMessage((long)data, outBuffer));
                    outBuffer.Clear();
                }
            }
            else if (nmt == NetworkMessageType.GameChange)
            {
                if (data == null)
                {
                    throw new InvalidStateException("SendAsync: data is null; expected GameWonMessage instance.");
                }

                this.sendRawData(NetworkMessageType.GameChange, (GameChangeMessage)data);
            }
            else if (nmt == NetworkMessageType.Authentication)
            {
                if (data == null)
                {
                    throw new InvalidStateException("SendAsync: data is null; expected Autentization instance.");
                }

                this.sendRawData(NetworkMessageType.Authentication, (Authentication)data);
            }
            else if (nmt == NetworkMessageType.SimulationTime)
            {
                if (data == null)
                {
                    throw new InvalidStateException("SendAsync: data is null; expected SimulationTimeMessage instance.");
                }

                this.sendRawData(NetworkMessageType.SimulationTime, (ListOfEventsMessage)data);
            }
            else if (nmt == NetworkMessageType.DisconnectRequest)
            {
                DisconnectRequest disconnectRequest = new DisconnectRequest(DateTime.Now);
                this.sendRawData(NetworkMessageType.DisconnectRequest, disconnectRequest);
            }
            else if (nmt == NetworkMessageType.DisconnectRequestConfirmation)
            {
                DisconnectRequestConfirmation disconnectRequest = new DisconnectRequestConfirmation(DateTime.Now);
                this.sendRawData(NetworkMessageType.DisconnectRequestConfirmation, disconnectRequest);
            }
            else if (nmt == NetworkMessageType.StartGame)
            {
                StartGame startGame = new StartGame(DateTime.Now);
                this.sendRawData(NetworkMessageType.StartGame, startGame);
            }
        }
Esempio n. 48
0
        private byte[] getByteDescriptorFromStream(MemoryStream stream, NetworkMessageType nmt)
        {
            byte[] outByteBuffer = new byte[stream.Length];
            stream.Read(outByteBuffer, 0, (int)stream.Length);

            BitConverter.GetBytes(outByteBuffer.Length).CopyTo(outByteDescriptor, 0);
            BitConverter.GetBytes((int)nmt).CopyTo(outByteDescriptor, 4);
            return outByteDescriptor;
        }
Esempio n. 49
0
		private void SendMessage (NetworkMessageType messageType, byte[] data, SendDataOptions options, NetworkGamer gamer)
		{

			NetOutgoingMessage om = peer.CreateMessage ();

			om.Write ((byte)messageType);
			om.Write (data);

			SendMessage (om, options, gamer);

		}
Esempio n. 50
0
 public NetworkEventArgs(NetIncomingMessage data, NetworkMessageType info)
 {
     _data = data;
     _info = info;
 }