예제 #1
0
        private void Server_DataReceived(IRemoteServer server, byte[] data)
        {
            lastServerHeartbeat = DateTime.UtcNow;

            foreach (var parsedData in NetworkDataParser.Parse(data))
            {
                switch (parsedData.Type)
                {
                case NetworkDataType.Request:
                    HandleRequest(parsedData as RequestData);
                    break;

                case NetworkDataType.Heartbeat:
                    // Last heartbeat time was set above.
                    break;

                case NetworkDataType.LobbyData:
                    UpdateLobbyData(parsedData as LobbyData);
                    break;

                // TODO: other data
                default:
                    // TODO: ignore? track safely?
                    throw new ExceptionFreeserf("Unknown server data");
                }
            }
        }
예제 #2
0
        private void Server_DataReceived(IRemoteServer server, byte[] data)
        {
            var parsedData = NetworkDataParser.Parse(data);

            switch (parsedData.Type)
            {
            case NetworkDataType.Request:
                HandleRequest(parsedData as RequestData);
                break;

            case NetworkDataType.Heartbeat:
                break;

            case NetworkDataType.LobbyData:
                UpdateLobbyData(parsedData as LobbyData);
                break;

            // TODO: other data
            default:
                // TODO: ignore? track safely?
                throw new ExceptionFreeserf("Unknown server data");
            }
        }
예제 #3
0
        void Server_DataReceived(IRemoteServer server, byte[] data)
        {
            Log.Verbose.Write(ErrorSystemType.Network, $"Received {data.Length} byte(s) of data from server '{server.Ip}'.");

            lastServerHeartbeat = DateTime.UtcNow;

            if (NetworkDataReceiver == null)
            {
                Log.Error.Write(ErrorSystemType.Application, "Network data receiver is not set up.");
                Disconnect();
                return;
            }

            if (serverState == ServerState.Offline)
            {
                serverState = ServerState.Lobby;
            }

            try
            {
                foreach (var parsedData in NetworkDataParser.Parse(data))
                {
                    Log.Verbose.Write(ErrorSystemType.Network, $"Received {parsedData.LogName} (message index {parsedData.MessageIndex}).");

                    switch (parsedData.Type)
                    {
                    case NetworkDataType.Heartbeat:
                        // Last heartbeat time was set above.
                        if (parsedData.MessageIndex != Global.SpontaneousMessage)
                        {
                            // If it has a message index, it is an answer to a heartbeat request.
                            NetworkDataReceiver.Receive(server, parsedData, null);
                        }
                        break;

                    case NetworkDataType.Request:
                    case NetworkDataType.LobbyData:
                    case NetworkDataType.SyncData:
                        NetworkDataReceiver.Receive(server, parsedData, (ResponseType responseType) => SendResponse(parsedData.MessageIndex, responseType));
                        break;

                    case NetworkDataType.Response:
                    case NetworkDataType.InSync:
                        NetworkDataReceiver.Receive(server, parsedData, null);
                        break;

                    case NetworkDataType.UserActionData:
                        Log.Error.Write(ErrorSystemType.Network, "User actions can't be send to a client.");
                        SendResponse(parsedData.MessageIndex, ResponseType.BadDestination);
                        break;

                    default:
                        Log.Error.Write(ErrorSystemType.Network, "Received unknown server data.");
                        SendResponse(parsedData.MessageIndex, ResponseType.BadRequest);
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Error.Write(ErrorSystemType.Network, "Error in receiving server data: " + ex.Message);
            }
        }