public void OnMatchEndedMessage(MatchEndedMessage endedMessage) { writeLine("-+-match ended. Winners json: " + Backtory.ToJson((endedMessage.Winners), true)); int previousLevel = PlayerPrefs.GetInt("MainLevel"); Application.LoadLevel(previousLevel); }
internal static readonly ISerializer jsonSerializer = new NewtonsoftJsonSerializer();/*new MyJsonSerializer();*/ internal Action <BacktoryResponse <T> > PrintCallBack <T>() where T : class { return((backtoryResponse) => { if (backtoryResponse.Successful) { ResultText.text = Backtory.ToJson(backtoryResponse.Body, true); /*JsonHelper.FormatJson(jsonSerializer.Serialize(backtoryResponse.Body));*/ } else { ResultText.text = backtoryResponse.Message; } }); }
public static GroupChatHistoryResponse Get(string responseJson) { A a = Backtory.FromJson <A> (responseJson); GroupChatHistoryResponse response = new GroupChatHistoryResponse(); List <ChatMessage> messageList = new List <ChatMessage>(); for (int i = 0; i < a.MessageList.Count; i++) { ComprehensiveChatMessage cCM = a.MessageList [i]; string cCMJson = Backtory.ToJson(cCM); if (cCM._type == ".SimpleChatMessage") { SimpleChatMessage sCM = Backtory.FromJson <SimpleChatMessage> (cCMJson); messageList.Add(sCM); } else if (cCM._type == ".ChatGroupUserAddedMessage") { UserAddedMessage sCM = Backtory.FromJson <UserAddedMessage> (cCMJson); messageList.Add(sCM); } else if (cCM._type == ".ChatGroupUserJoinedMessage") { UserJoinedMessage sCM = Backtory.FromJson <UserJoinedMessage> (cCMJson); messageList.Add(sCM); } else if (cCM._type == ".ChatGroupUserLeftMessage") { UserLeftMessage sCM = Backtory.FromJson <UserLeftMessage> (cCMJson); messageList.Add(sCM); } else if (cCM._type == ".ChatGroupUserRemovedMessage") { UserRemovedMessage sCM = Backtory.FromJson <UserRemovedMessage> (cCMJson); messageList.Add(sCM); } else if (cCM._type == ".ChatGroupInvitationMessage") { ChatInvitationMessage sCM = Backtory.FromJson <ChatInvitationMessage> (cCMJson); messageList.Add(sCM); } else { // ERROR } } response.ChatMessageList = messageList; return(response); }
public Dictionary <string, object> sendNoWait(string destination, Dictionary <string, object> jsonData, Dictionary <string, string> extraHeader) { if (!isConnected()) { throw new Exception("WS is not connected"); } string jsonstring = Backtory.ToJson(jsonData); webSocket.Send(destination, jsonstring, extraHeader); Dictionary <string, object> result = new Dictionary <string, object> (); result.Add("success", "message sent"); return(result); }
public void OnChallengeInvitation(ChallengeInvitationMessage message) { lastChallengeInvitationId = message.ChallengeId; writeLine("---challenge invitation to " + message.ChallengeId + " by " + message.ChallengerId + " with challenged users " + Backtory.ToJson(message.challengedUsers, true)); }
public void OnException(ExceptionMessage exception) { writeLine("---Exception: " + Backtory.ToJson((exception), true)); }
public void OnChallengeReady(ChallengeReadyMessage message) { writeLine("---challenge ready " + message.ChallengeId + " and all info json: " + Backtory.ToJson(message, true)); LastFoundedGameId = message.MatchId; ExecuteOnMainThread.Enqueue(() => { SceneManager.LoadScene("GameScene"); }); }
public void OnMasterMessage(MasterMessage masterMessage) { writeLine("-+-master message " + masterMessage.Message + " with data json " + Backtory.ToJson((masterMessage), true)); }
public void OnMatchEvent(MatchEvent evt) { writeLine("-+- match event with message " + evt.Message + " from " + evt.UserId + " with data json " + Backtory.ToJson((evt.Data), true)); }
public void OnMatchJoinedMessage(MatchJoinedMessage message) { writeLine("-+-user " + message.UserId + ":" + message.Username + " joined to match. All joined json: " + Backtory.ToJson((message.ConnectedUserIds), true)); }
private static void SaveAsCurrentUserInMemoryAndStorage(BacktoryUser user) { currentUser = user; Backtory.Storage.Put(KeyUsername, user.Username); Backtory.Storage.Put(KeyCurrentUser, Backtory.ToJson(user)); }
// Important note: private static void SaveLoginInfo(LoginResponse loginResponse) { Backtory.Storage.Put(KeyLoginInfo, Backtory.ToJson(loginResponse)); }
public void onCurrentUserClick() { ResultText.text = Backtory.ToJson(BacktoryUser.GetCurrentUser(), true); }
public void OnChallengeDeclined(ChallengeDeclinedMessage message) { writeLine("---challenge " + message.ChallengeId + " declined by " + message.DeclinedId + " and all info json: " + Backtory.ToJson(message, true)); }
private void addClickListeners() { btnCreatePri.onClick.AddListener(() => { createChatGroup(ChatGroupType.Private); }); btnCreatePub.onClick.AddListener(() => { createChatGroup(ChatGroupType.Public); }); btnListGroups.onClick.AddListener(() => { BacktoryResponse <ChatGroupsListResponse> response = backtoryApi.RequestListOfChatGroups(); if (response.Successful) { writeLine("--+group list returned with json: " + Backtory.ToJson(response.Body, true)); } else { writeLine("--+group list failed with code: " + response.Code + " and message " + response.Message); } }); btnListMembers.onClick.AddListener(() => { BacktoryResponse <ChatGroupMembersListResponse> response = backtoryApi.RequestListOfChatGroupMembers(getGroupId()); if (response.Successful) { writeLine("--+group member list returned with json: " + Backtory.ToJson(response.Body, true)); } else { writeLine("--+group member list failed with code: " + response.Code + " and message " + response.Message); } }); btnAddMember.onClick.AddListener(() => { BacktoryResponse <BacktoryVoid> response = backtoryApi.AddMemberToChatGroup(getGroupId(), getUserId()); if (response.Successful) { writeLine("--+member added"); } else { writeLine("--+member adding failed with code: " + response.Code + " and message " + response.Message); } }); btnRemoveMember.onClick.AddListener(() => { BacktoryResponse <BacktoryVoid> response = backtoryApi.RemoveMemberFromChatGroup(getGroupId(), getUserId()); if (response.Successful) { writeLine("--+member removed"); } else { writeLine("--+member removing failed with code: " + response.Code + " and message " + response.Message); } }); btnAddOwner.onClick.AddListener(() => { BacktoryResponse <BacktoryVoid> response = backtoryApi.AddOwnerToChatGroup(getGroupId(), getUserId()); if (response.Successful) { writeLine("--+owner added"); } else { writeLine("--+owner adding failed with code: " + response.Code + " and message " + response.Message); } }); btnGroupChat.onClick.AddListener(() => { BacktoryResponse <BacktoryVoid> response = backtoryApi.SendChatToGroup(getGroupId(), getMessage()); if (response.Successful) { writeLine("--+group chat sent"); } else { writeLine("--+group chat sending failed with code: " + response.Code + " and message " + response.Message); } }); btnDirectChat.onClick.AddListener(() => { BacktoryResponse <BacktoryVoid> response = backtoryApi.SendChatToUser(getUserId(), getMessage()); if (response.Successful) { writeLine("--+direct chat sent"); } else { writeLine("--+direct chat sending failed with code: " + response.Code + " and message " + response.Message); } }); btnJoin.onClick.AddListener(() => { string groupId = getGroupId(); BacktoryResponse <BacktoryVoid> response = backtoryApi.JoinChatGroup(groupId); if (response.Successful) { writeLine("--+you joined to group with id " + groupId); } else { writeLine("--+group creation failed with code: " + response.Code + " and message " + response.Message); } }); btnLeave.onClick.AddListener(() => { BacktoryResponse <BacktoryVoid> response = backtoryApi.LeaveChatGroup(getGroupId()); if (response.Successful) { writeLine("--+you left chat group"); } else { writeLine("--+group leaving failed with code: " + response.Code + " and message " + response.Message); } }); btnInvite.onClick.AddListener(() => { BacktoryResponse <BacktoryVoid> response = backtoryApi.InviteUserToChatGroup(getGroupId(), getUserId()); if (response.Successful) { writeLine("--+invitation sent"); } else { writeLine("--+invitation sending failed with code: " + response.Code + " and message " + response.Message); } }); btnOffline.onClick.AddListener(() => { BacktoryResponse <OfflineMessageResponse> response = backtoryApi.RequestOfflineMessages(); if (response.Successful) { writeLine("--+offline list: "); List <ChatMessage> list = response.Body.ChatMessageList; for (int i = 0; i < list.Count; i++) { list[i].OnMessageReceived(this); } } else { writeLine("--+offline request failed with code: " + response.Code + " and message " + response.Message); } }); btnGroupHist.onClick.AddListener(() => { BacktoryResponse <GroupChatHistoryResponse> response = backtoryApi.RequestGroupChatHistory(getGroupId(), lastGroupDate); if (response.Successful) { writeLine("--+group history"); List <ChatMessage> list = response.Body.ChatMessageList; if (list.Count > 0) { lastGroupDate = list[list.Count - 1].Date; } else { lastGroupDate = 0; } for (int i = 0; i < list.Count; i++) { list[i].OnMessageReceived(this); } } else { writeLine("--+group history request failed with code: " + response.Code + " and message " + response.Message); } }); btnDirectHist.onClick.AddListener(() => { BacktoryResponse <UserChatHistoryResponse> response = backtoryApi.RequestUserChatHistory(lastDirectDate); if (response.Successful) { writeLine("--+direct history"); List <ChatMessage> list = response.Body.ChatMessageList; if (list.Count > 0) { lastDirectDate = list[list.Count - 1].Date; } else { lastDirectDate = 0; } for (int i = 0; i < list.Count; i++) { list[i].OnMessageReceived(this); } } else { writeLine("--+direct history request failed with code: " + response.Code + " and message " + response.Message); } }); btnReturn.onClick.AddListener(() => { int previousLevel = PlayerPrefs.GetInt("MainLevel"); Application.LoadLevel(previousLevel); }); }
private void addClickListeners() { btnLogin.onClick.AddListener(() => { string username = ifUsername.text; string password = ifPassword.text; BacktoryUser.LoginInBackground(username, password, loginResponse => { if (loginResponse.Successful) { writeLine("logged in!"); } else { writeLine("Unable to login=> " + loginResponse.Code + ":" + loginResponse.Message); } }); }); btnConnect.onClick.AddListener(() => { Debug.Log("AccessToken: " + BacktoryUser.GetAccessToken()); if (BacktoryUser.GetAccessToken() == null) { writeLine("login first"); return; } connect(); }); btnDisconnect.onClick.AddListener(() => { BacktoryResponse <BacktoryVoid> response = backtoryApi.Disconnect(); if (response.Successful) { writeLine("---disconnect successful"); } else { writeLine("---disconnect failed with code: " + response.Code + " and message " + response.Message); } }); btnMatchmaking.onClick.AddListener(() => { BacktoryResponse <MatchmakingResponse> response = backtoryApi.RequestMatchmaking(matchmakingName, 55, "sample meta data"); if (response.Successful) { lastMatchmakingRequestId = response.Body.RequestId; writeLine("---matchmaking successful. id: " + lastMatchmakingRequestId); } else { writeLine("---matchmaking failed with code: " + response.Code + " and message " + response.Message); } }); btnCancelMM.onClick.AddListener(() => { BacktoryResponse <BacktoryVoid> response = backtoryApi.CancelMatchmaking(matchmakingName, lastMatchmakingRequestId); if (response.Successful) { writeLine("---matchmaking cancelled successful."); } else { writeLine("---matchmaking cancellation failed with code: " + response.Code + " and message " + response.Message); } }); btnChallenge.onClick.AddListener(() => { List <String> users = new List <String> (); users.Add("5720b016e4b0bf11f90cdee6"); // ali users.Add("5720b01be4b0bf11f90cdee7"); // mamad users.Add("5720b01ee4b0bf11f90cdee8"); // farib BacktoryResponse <ChallengeResponse> response = backtoryApi.RequestChallenge(users, 15, 2); if (response.Successful) { writeLine("---challenge request successful. challenge id: " + response.Body.ChallengeId); } else { writeLine("---challenge request failed with code: " + response.Code + " and message " + response.Message); } }); btnChallengeList.onClick.AddListener(() => { BacktoryResponse <ActiveChallengesListResponse> response = backtoryApi.RequestListOfActiveChallenges(); if (response.Successful) { writeLine("---active challenges list json: " + Backtory.ToJson((response.Body), true)); } else { writeLine("---active challenges list failed with code: " + response.Code + " and message " + response.Message); } }); btnAccept.onClick.AddListener(() => { BacktoryResponse <BacktoryVoid> response = backtoryApi.AcceptChallenge(lastChallengeInvitationId); if (response.Successful) { writeLine("---challenge accepted successful."); } else { writeLine("---accepting challenge failed with code: " + response.Code + " and message " + response.Message); } }); btnDecline.onClick.AddListener(() => { BacktoryResponse <BacktoryVoid> response = backtoryApi.DeclineChallenge(lastChallengeInvitationId); if (response.Successful) { writeLine("---challenge declined successful."); } else { writeLine("---declining challenge failed with code: " + response.Code + " and message " + response.Message); } }); btnChat.onClick.AddListener(() => SceneManager.LoadScene("ChatScene")); }
public void OnMatchNotFound(MatchNotFoundMessage message) { writeLine("---match not found with json " + Backtory.ToJson(message, true)); }
public void OnMatchUpdate(MatchUpdateMessage message) { writeLine("---match update with json " + Backtory.ToJson(message, true)); }
public void OnMatchFound(MatchFoundMessage message) { LastFoundedGameId = message.MatchId; writeLine("---match found with json: " + Backtory.ToJson(message, true)); SceneManager.LoadScene("GameScene"); }