Пример #1
0
        public bool SendGameStateMessage(GameState state)
        {
            var socket = _communicationSockets[state.Player.ID];

            if (!socket.Connected)
            {
                return(false);
            }
            var message = new Message(MessageType.GameState, SerializationUtilities.ToByteArray(state));

            Message.SendMessage(message, socket);
            return(true);
        }
Пример #2
0
        protected async Task StartReceiverAsync(Socket socket, int playerNumber)
        {
            while (_runReceivers)
            {
                await Task.Delay(1);

                var message = Message.ReceiveMessage(socket);
                if (message.MessageType == MessageType.NodeUpgradeRequest)
                {
                    var request = SerializationUtilities.FromByteArray <NodeUpgradeRequest>(message.Data);
                    _handler.HandleNodeUpgradeRequestMessage(request, playerNumber);
                }
            }
        }
Пример #3
0
        protected async Task StartReceiverAsync(Socket socket)
        {
            while (_runReceiver)
            {
                await Task.Delay(1);

                var message = Message.ReceiveMessage(socket);
                if (message.MessageType == MessageType.GameState)
                {
                    var state = SerializationUtilities.FromByteArray <GameState>(message.Data);
                    _handler.HandleGameStateMessage(state);
                }
            }
        }
Пример #4
0
        public void SendAttackRequest(NodeUpgradeRequest request)
        {
            var message = new Message(MessageType.NodeUpgradeRequest, SerializationUtilities.ToByteArray(request));

            Message.SendMessage(message, _commsSocket);
        }