private void OnWebRpcResponse(WebRpcResponse response) { if (response.ReturnCode != 0) { Debug.Log(response.ToStringFull()); // in an error case, it's often helpful to see the full response return; } if (response.Name.Equals("GetGameList")) { this.SavedGames.Clear(); if (response.Parameters == null) { Debug.Log("WebRpcResponse for GetGameList contains no rooms: " + response.ToStringFull()); return; } // the response for GetGameList contains a Room's name as Key and another Dictionary<string,object> with the values the web service sends foreach (KeyValuePair <string, object> pair in response.Parameters) { // per key (room name), we send // "ActorNr" which is the PlayerId/ActorNumber this user had in the room // "Properties" which is another Dictionary<string,object> with the properties that the lobby sees Dictionary <string, object> roomValues = pair.Value as Dictionary <string, object>; int savedActorNumber = (int)roomValues["ActorNr"]; Dictionary <string, object> savedRoomProps = roomValues["Properties"] as Dictionary <string, object>; // we are not yet using these in this demo this.SavedGames.Add(pair.Key, savedActorNumber); Debug.Log(pair.Key + " actorNr: " + savedActorNumber + " props: " + SupportClass.DictionaryToString(savedRoomProps)); } } }
private void OnWebRpcResponse(WebRpcResponse response) { if (response.ReturnCode != 0) { Debug.Log(response.ToStringFull()); // in an error case, it's often helpful to see the full response return; } }
private void OnWebRpcResponse(WebRpcResponse response) { Debug.Log(string.Format("OnWebRpcResponse. Code: {0} Content: {1}", response.ReturnCode, SupportClass.DictionaryToString(response.Parameters))); if (response.ReturnCode == 0) { if (response.Parameters == null) { Debug.Log("WebRpc executed ok but didn't get content back. This happens for empty save-game lists."); memoryGui.GameListUpdate(); return; } if (response.Name.Equals("GetGameList")) { this.SavedGames.Clear(); // the response for GetGameList contains a Room's name as Key and another Dictionary<string,object> with the values the web service sends foreach (KeyValuePair <string, object> pair in response.Parameters) { // per key (room name), we send // "ActorNr" which is the PlayerId/ActorNumber this user had in the room // "Properties" which is another Dictionary<string,object> with the properties that the lobby sees Dictionary <string, object> roomValues = pair.Value as Dictionary <string, object>; SaveGameInfo si = new SaveGameInfo(); si.RoomName = pair.Key; si.DisplayName = pair.Key; // we might have a better display name for this room. see below. si.MyPlayerId = (int)roomValues["ActorNr"]; si.AvailableProperties = roomValues["Properties"] as Dictionary <string, object>; // let's find out of it's our turn to play and if we know the opponent's name (which we will display as game name). if (si.AvailableProperties != null) { // PropTurn is a value per room that gets set to the player who's turn is next. if (si.AvailableProperties.ContainsKey(PropTurn)) { int nextPlayer = (int)si.AvailableProperties[PropTurn]; si.MyTurn = nextPlayer == si.MyPlayerId; } // PropNames is set to a list of the player names. this can easily be turned into a name for the game to display if (si.AvailableProperties.ContainsKey(PropNames)) { string display = (string)si.AvailableProperties[PropNames]; display = display.ToLower(); display = display.Replace(this.PlayerName.ToLower(), ""); display = display.Replace(";", ""); si.DisplayName = "vs. " + display; } } //Debug.Log(si.ToStringFull()); this.SavedGames.Add(si); } memoryGui.GameListUpdate(); } } }
public void OnWebRpcResponse(OperationResponse response) { Debug.LogFormat("WebRPC operation response {0}", response.ToStringFull()); switch (response.ReturnCode) { case ErrorCode.Ok: WebRpcResponse webRpcResponse = new WebRpcResponse(response); Debug.LogFormat("Parsed WebRPC response {0}", response.ToStringFull()); if (string.IsNullOrEmpty(webRpcResponse.Name)) { Debug.LogError("Unexpected: WebRPC response did not contain WebRPC method name"); } if (webRpcResponse.ResultCode == 0) // success 成功 { switch (webRpcResponse.Name) { // todo: add your code here 待办事项:在这里添加代码 case GetGameListWebRpcMethodName: // example 例子 // ... break; } } else if (webRpcResponse.ResultCode == -1) { Debug.LogErrorFormat("Web server did not return ResultCode for WebRPC method=\"{0}\", Message={1}", webRpcResponse.Name, webRpcResponse.Message); } else { Debug.LogErrorFormat("Web server returned ResultCode={0} for WebRPC method=\"{1}\", Message={2}", webRpcResponse.ResultCode, webRpcResponse.Name, webRpcResponse.Message); } break; case ErrorCode.ExternalHttpCallFailed: // web service unreachable web服务不可访问 Debug.LogErrorFormat("WebRPC call failed as request could not be sent to the server. {0}", response.DebugMessage); break; case ErrorCode.HttpLimitReached: // too many WebRPCs in a short period of time 在短时间内太多的WebRPCs // the debug message should contain the limit exceeded 调试消息应该包含超出的限制 Debug.LogErrorFormat("WebRPCs rate limit exceeded: {0}", response.DebugMessage); break; case ErrorCode.InvalidOperation: // WebRPC not configured at all OR not configured properly OR trying to send on name server WebRPC根本没有配置或配置不正确或试图在名称服务器上发送 if (PhotonNetwork.Server == ServerConnection.NameServer) { Debug.LogErrorFormat("WebRPC not supported on NameServer. {0}", response.DebugMessage); } else { Debug.LogErrorFormat("WebRPC not properly configured or not configured at all. {0}", response.DebugMessage); } break; default: // other unknown error, unexpected 其他未知错误,意外 Debug.LogErrorFormat("Unexpected error, {0} {1}", response.ReturnCode, response.DebugMessage); break; } }
public void OnWebRpcResponse(WebRpcResponse webResponse) { switch (webResponse.Name) { case RPC_GET_GAMELIST: OnGetGameListResponse(webResponse.Parameters); break; case RPC_GET_GAMES: OnGetGamesResponse(webResponse.Parameters); break; case RPC_GET_PLAYER: OnPlayerLoadResponse(webResponse.Parameters); break; case RPC_POST_PLAYER: OnPlayerSaveResponse(); break; } }
public override void OnWebRpcResponse(OperationResponse response) { this.Log("WebRpc:" + response.ToStringFull()); if (response.ReturnCode == null) { return; } WebRpcResponse webRpcResponse = new WebRpcResponse(response); if (webRpcResponse.ReturnCode != 0) { this.Log("WebRPC '" + webRpcResponse.Name + "' に失敗しました. Error: " + (object)webRpcResponse.ReturnCode + " Message: " + webRpcResponse.DebugMessage); } using (Dictionary <string, object> .Enumerator enumerator = webRpcResponse.Parameters.GetEnumerator()) { while (enumerator.MoveNext()) { KeyValuePair <string, object> current = enumerator.Current; this.Log("Key:" + current.Key + "/ Value:" + current.Value); } } }
private void OnWebRpcResponse(WebRpcResponse response) { Debug.Log(string.Format("OnWebRpcResponse. Code: {0} Content: {1}", response.ReturnCode, SupportClass.DictionaryToString(response.Parameters))); if (response.ReturnCode == 0) { if (response.Parameters == null) { Debug.Log("WebRpc executed ok but didn't get content back. This happens for empty save-game lists."); memoryGui.GameListUpdate(); return; } if (response.Name.Equals("GetGameList")) { this.SavedGames.Clear(); // the response for GetGameList contains a Room's name as Key and another Dictionary<string,object> with the values the web service sends foreach (KeyValuePair<string, object> pair in response.Parameters) { // per key (room name), we send // "ActorNr" which is the PlayerId/ActorNumber this user had in the room // "Properties" which is another Dictionary<string,object> with the properties that the lobby sees Dictionary<string, object> roomValues = pair.Value as Dictionary<string, object>; SaveGameInfo si = new SaveGameInfo(); si.RoomName = pair.Key; si.DisplayName = pair.Key; // we might have a better display name for this room. see below. si.MyPlayerId = (int)roomValues["ActorNr"]; si.AvailableProperties = roomValues["Properties"] as Dictionary<string, object>; // let's find out of it's our turn to play and if we know the opponent's name (which we will display as game name). if (si.AvailableProperties != null) { // PropTurn is a value per room that gets set to the player who's turn is next. if (si.AvailableProperties.ContainsKey(PropTurn)) { int nextPlayer = (int) si.AvailableProperties[PropTurn]; si.MyTurn = nextPlayer == si.MyPlayerId; } // PropNames is set to a list of the player names. this can easily be turned into a name for the game to display if (si.AvailableProperties.ContainsKey(PropNames)) { string display = (string)si.AvailableProperties[PropNames]; display = display.ToLower(); display = display.Replace(this.NickName.ToLower(), ""); display = display.Replace(";", ""); si.DisplayName = "vs. " + display; } } //Debug.Log(si.ToStringFull()); this.SavedGames.Add(si); } memoryGui.GameListUpdate(); } } }
public override void OnOperationResponse(OperationResponse operationResponse) { base.OnOperationResponse(operationResponse); // important to call, to keep state up to date if (operationResponse.ReturnCode != ErrorCode.Ok) { this.DebugReturn(DebugLevel.ERROR, operationResponse.ToStringFull() + " " + this.State); } logger.Append(String.Format("---OperationResponse:")); logger.Append(String.Format(" |Code: {0}", OperationCodeLookup.NameOf[operationResponse.OperationCode])); logger.Append(String.Format(" |ReturnCode: {0}", operationResponse.ReturnCode)); switch (operationResponse.OperationCode) { case OperationCode.Authenticate: break; case OperationCode.JoinLobby: break; case OperationCode.JoinRandomGame: break; case OperationCode.JoinGame: case OperationCode.CreateGame: if (this.State == ClientState.Joined) { this.cache.ActorNr = (int)operationResponse.Parameters[ParameterCode.ActorNr]; } break; case OperationCode.GetProperties: logger.Append(operationResponse.ToStringFull()); break; case OperationCode.SetProperties: //logger.Append(operationResponse.ToStringFull()); opResponseHandler.OnSetPropertiesResponse(); break; case OperationCode.RaiseEvent: break; case OperationCode.Rpc: WebRpcResponse webResponse = new WebRpcResponse(operationResponse); if (operationResponse.ReturnCode != 0) { DebugReturn(DebugLevel.ERROR, "WebRpc failed. Response: " + operationResponse.ToStringFull()); DebugReturn(DebugLevel.ERROR, "WebRpc '" + webResponse.Name + "' failed. Error: " + webResponse.ReturnCode + " Message: " + webResponse.DebugMessage); } else { webrpcHandler.OnWebRpcResponse(webResponse); } break; } logger.Flush(); }
private void OnWebRpcResponse(WebRpcResponse response) { Debug.Log("[DemoGame] OnWebRpcResponse: " + response.ToStringFull()); if (response.ReturnCode != 0) { Debug.Log(response.ToStringFull()); // in an error case, it's often helpful to see the full response return; } if (response.Name.Equals("GetGameList")) { this.SavedGames.Clear(); if (response.Parameters == null) { Debug.Log("WebRpcResponse for GetGameList contains no rooms: " + response.ToStringFull()); return; } // the response for GetGameList contains a Room's name as Key and another Dictionary<string,object> with the values the web service sends foreach (KeyValuePair<string, object> pair in response.Parameters) { // per key (room name), we send // "ActorNr" which is the PlayerId/ActorNumber this user had in the room // "Properties" which is another Dictionary<string,object> with the properties that the lobby sees Dictionary<string, object> roomValues = pair.Value as Dictionary<string, object>; int savedActorNumber = (int)roomValues["ActorNr"]; Dictionary<string, object> savedRoomProps = roomValues["Properties"] as Dictionary<string, object>; // we are not yet using these in this demo this.SavedGames.Add(pair.Key, savedActorNumber); Debug.Log(pair.Key + " actorNr: " + savedActorNumber + " props: " + SupportClass.DictionaryToString(savedRoomProps)); } } }
public void OnWebRpcResponse(WebRpcResponse webResponse) { if (webResponse.ReturnCode != 0) { DebugReturn(DebugLevel.ERROR, "WebRpc '" + webResponse.Name + "' failed. Error: " + webResponse.ReturnCode + " Message: " + webResponse.DebugMessage); return; } switch (webResponse.Name) { case "GetGameList": roomList = new List<string>(); actorList = new List<int>(); var data = webResponse.Parameters; if (data != null) { foreach (var item in data) { roomList.Add(item.Key); actorList.Add(int.Parse((string)item.Value)); Console.WriteLine("Got room:{0} actor#:{1}", item.Key, item.Value); } } else { Console.WriteLine(@"N\A - empty list"); } break; } }
public override void OnOperationResponse(OperationResponse operationResponse) { base.OnOperationResponse(operationResponse); // important to call, to keep state up to date if (operationResponse.ReturnCode != ErrorCode.Ok) { this.DebugReturn(DebugLevel.ERROR, operationResponse.ToStringFull() + " " + this.State); } switch (operationResponse.OperationCode) { case OperationCode.Authenticate: break; case OperationCode.JoinRandomGame: break; case OperationCode.JoinGame: case OperationCode.CreateGame: if (this.State == ClientState.Joined) { this.actorNr = (int)operationResponse.Parameters[ParameterCode.ActorNr]; } break; case OperationCode.Rpc: if (operationResponse.ReturnCode != 0) { DebugReturn(DebugLevel.ERROR, "WebRpc failed. Response: " + operationResponse.ToStringFull()); } else { WebRpcResponse webResponse = new WebRpcResponse(operationResponse); this.OnWebRpcResponse(webResponse); } break; } }
// 接收WebRPC回傳 void OnWebRpcResponse(OperationResponse operationResponse) { if (operationResponse.ReturnCode != 0) { Debug.Log("WebRPC 操作失敗. Response: " + operationResponse.ToStringFull()); transformStatus = "finished"; waitProcess = ""; listenStatus = "finished"; ChangbuttonOnOrOff(true); return; } WebRpcResponse webRpcResponse = new WebRpcResponse(operationResponse); if (webRpcResponse.ReturnCode != 0) { Debug.Log("WebRPC '" + webRpcResponse.Name + "發生問題. Error: " + webRpcResponse.ReturnCode + " Message: " + webRpcResponse.DebugMessage); return; } Dictionary <string, object> parameters = webRpcResponse.Parameters; foreach (KeyValuePair <string, object> pair in parameters) { countObject++; if (countObject == parameters.Count) { tempReturnValue += string.Format(@"""{0}"" : ""{1}""", pair.Key, pair.Value); } else { tempReturnValue += string.Format(@"""{0}"" : ""{1}""", pair.Key, pair.Value) + ", "; } } //判斷事件 if ((string)parameters["callnumber"] == "1") { contractStatus = JsonUtility.FromJson <ContractStatus>("{" + tempReturnValue + "}"); } else if ((string)parameters["callnumber"] == "2") { listenEvent_New = JsonUtility.FromJson <ListenEvent_New>("{" + tempReturnValue + "}"); waitMessage = false; listenStatus = "finished"; } else if ((string)parameters["callnumber"] == "3") { allowance = JsonUtility.FromJson <Allowance>("{" + tempReturnValue + "}"); transformStatus = "finished"; waitProcess = ""; listenStatus = "finished"; ChangbuttonOnOrOff(true); CheckBalanceOf(); } else if ((string)parameters["callnumber"] == "4") { balanceOf = JsonUtility.FromJson <BalanceOf>("{" + tempReturnValue + "}"); transformStatus = "finished"; waitProcess = ""; listenStatus = "finished"; ChangbuttonOnOrOff(true); } else if ((string)parameters["callnumber"] == "5") { giveApprove = JsonUtility.FromJson <GiveApprove>("{" + tempReturnValue + "}"); transformStatus = "finished"; waitProcess = ""; listenStatus = "finished"; ChangbuttonOnOrOff(true); } else if ((string)parameters["callnumber"] == "6") { twoPointDeal = JsonUtility.FromJson <TwoPointDeal>("{" + tempReturnValue + "}"); transformStatus = "finished"; waitProcess = ""; listenStatus = "finished"; ChangbuttonOnOrOff(true); } else if ((string)parameters["callnumber"] == "7") { putExchange = JsonUtility.FromJson <PutExchange>("{" + tempReturnValue + "}"); transformStatus = "finished"; waitProcess = ""; listenStatus = "finished"; ChangbuttonOnOrOff(true); } else if ((string)parameters["callnumber"] == "8") { lookExchange_Self = JsonUtility.FromJson <LookExchange_Self>("{" + tempReturnValue + "}"); transformStatus = "finished"; waitProcess = ""; listenStatus = "finished"; ChangbuttonOnOrOff(true); CheckBalanceOf(); } else if ((string)parameters["callnumber"] == "9") { lookExchange_Other = JsonUtility.FromJson <LookExchange_Other>("{" + tempReturnValue + "}"); transformStatus = "finished"; waitProcess = ""; listenStatus = "finished"; ChangbuttonOnOrOff(true); StartLookExchange_Self(); } else if ((string)parameters["callnumber"] == "10") { exchangeStatus = JsonUtility.FromJson <ExchangeStatus>("{" + tempReturnValue + "}"); transformStatus = "finished"; waitProcess = ""; listenStatus = "finished"; ChangbuttonOnOrOff(true); } else if ((string)parameters["callnumber"] == "11") { cancelExchange = JsonUtility.FromJson <CancelExchange>("{" + tempReturnValue + "}"); transformStatus = "finished"; waitProcess = ""; listenStatus = "finished"; ChangbuttonOnOrOff(true); } else if ((string)parameters["callnumber"] == "12") { exchangeItem = JsonUtility.FromJson <ExchangeItem>("{" + tempReturnValue + "}"); transformStatus = "finished"; waitProcess = ""; listenStatus = "finished"; ChangbuttonOnOrOff(true); } else if ((string)parameters["callnumber"] == "13") { buyLottery = JsonUtility.FromJson <BuyLottery>("{" + tempReturnValue + "}"); transformStatus = "finished"; waitProcess = ""; listenStatus = "finished"; ChangbuttonOnOrOff(true); } else if ((string)parameters["callnumber"] == "14") { lookLottery = JsonUtility.FromJson <LookLottery>("{" + tempReturnValue + "}"); transformStatus = "finished"; waitProcess = ""; listenStatus = "finished"; ChangbuttonOnOrOff(true); CheckBalanceOf(); } //清空暫存內容 countObject = 0; tempReturnValue = ""; }