コード例 #1
0
    private bool onUserEnter(DataMessage message)
    {
        message.createReader();
        Dictionary<string, object> json = message.readJson();
        message.closeReader();

        ChatUser u = new ChatUser();
        if (u.fromJson(json))
        {
            if (u.userId == systemController.getUserInfo().userId)
            {
                postUpdate(UiUpdates.GameIsReady, null);
            }
            else
            {
                if (!users.ContainsKey(u.userId))
                {
                    users.Add(u.userId, u);
                }
                postUpdate(UiUpdates.NewUser, u);
            }
        }

        return false;
    }
コード例 #2
0
    private bool onReceivePlayersList(DataMessage message)
    {
        message.createReader();
        int callback = message.readInt32();

        if (callback != myCallback)
        {
            Debug.LogError("receive users list, but invalid Callback");
        }

        Dictionary<string, object> json = message.readJson();
        message.closeReader();
        object[] usersJson = (object[])json["users"];
        for (int i = 0; i < usersJson.Length; i++)
        {
            ChatUser u = new ChatUser();
            if (u.fromJson((Dictionary<string, object>)usersJson[i]))
            {
                users[u.userId] = u;
            }
        }
        postUpdate(UiUpdates.UpdateUsersList, null);
        sendUserReady();
        return false;
    }
コード例 #3
0
    private bool onReceiveUserInfo(DataMessage message)
    {
        message.createReader();
        int callback = message.readInt32();
        int result = message.readInt32();

        switch(result) {
            case Ids.SystemResults.SUCCESS:
                {
                    int requestedUsedId = message.readInt32();
                    Dictionary<string, object> json = message.readJson();
                    message.closeReader();

                    ChatUser user;
                    if (users.ContainsKey(requestedUsedId))
                    {
                        user = users[requestedUsedId];
                    }
                    else
                    {
                        user = new ChatUser();
                        users.Add(requestedUsedId, user);
                    }
                    if (!user.fromJson(json))
                    {
                        Debug.LogError("ReceiveUserInfo : fail to parse user data for "+requestedUsedId.ToString());
                        user.setUnknown(requestedUsedId);
                    }
                    postUpdate(UiUpdates.UserUpdated, user);
                }
                break;
            case Ids.Actions.SimpleChat.RESULT_NO_USER_WITH_SUCH_ID:
                {
                    int requestedUsedId = message.readInt32();
                    message.closeReader();
                    Debug.LogError("ReceiveUserInfo : requested User not found id: " + requestedUsedId.ToString());
                }
                break;
            case Ids.SystemResults.INVALID_SESSION:
                message.closeReader();
                Debug.LogError("ReceiveUserInfo : Internal error - Invalid session");
                break;
            case Ids.SystemResults.INVALID_DATA:
                message.closeReader();
                Debug.LogError("ReceiveUserInfo : Internal error - Invalid data");
                break;
            case Ids.SystemResults.NO_GAME_WITH_SUCH_ID:
                message.closeReader();
                Debug.LogError("ReceiveUserInfo : Internal error - no game with such id");
                break;
        }

        return false;
    }
コード例 #4
0
    private bool onGameFinished(DataMessage message)
    {
        if (state != SystemControllerStates.InGame)
            throw new InvalidOperationException("Invalid SystemController state, waiting InGame), but have : " + state);

        if (message != null && message.Data != null)
        {
            message.createReader();
            int gameId = message.readInt32();
            int result = message.readInt32();
            Dictionary<string, object> data = message.readJson();
            message.closeReader();

            if (gameId == currentGame.GameId)
            {
                state = SystemControllerStates.Default;
                currentGame.finishGame(result, data);
            }
            else
            {

            }
        }
        return true;
    }