private void LoadCallback(IHttpResponse httpResponse, object userState) { string errorMsg; WebhooksResponse response; ICreateGameCallInfo callInfo = (ICreateGameCallInfo)httpResponse.CallInfo; if (this.TryGetForwardResponse(httpResponse, out response, out errorMsg)) { if (response.ResultCode == 0) { if (response.State != null) { try { if (!this.PluginHost.SetGameState(response.State)) { callInfo.Fail(string.Format("Failed to load state from {0}.", httpResponse.Request.Url)); } else { this.SuccesfullLoaded = true; callInfo.Continue(); } } catch (Exception ex) { try { callInfo.Fail(string.Format("Failed to load state from {0} : Exception='{1}'", httpResponse.Request.Url, ex.Message)); } catch (Exception e) { this.ReportError(string.Format("Failed to load state from {0} : Exception='{1}'.", httpResponse.Request.Url, e)); } this.ReportError(string.Format("Failed to load state from {0} : Exception='{1}'.", httpResponse.Request.Url, ex)); } } else { // should only be tha case for join with CreateIfNotExists, (we should probably have a reload flag) this.PluginHost.LogDebug("Creating Game without loading any state - Rejoins will fail!"); this.SuccesfullLoaded = true; callInfo.Continue(); } } else { var msg = string.Format("Failed to load state from {0} : {1} {2}", httpResponse.Request.Url, response.ResultCode, response.Message); this.ReportError(msg); callInfo.Fail(msg); } } else { var msg = string.Format("Failed to load state from {0} : {1}", httpResponse.Request.Url, errorMsg); this.ReportError(msg); callInfo.Fail(msg); } }
public override void OnCreateGame(ICreateGameCallInfo info) { ++this.CallsCount; try { this.CheckICreateGameCallInfo(info); this.CheckBeforeCreateGame(); } catch (Exception e) { info.Fail(e.ToString()); return; } try { base.OnCreateGame(info); this.CheckAfterCreateGame(); } catch (Exception e) { var msg = e.ToString(); this.PluginHost.BroadcastErrorInfoEvent(msg, info); } }
public override void OnCreateGame(ICreateGameCallInfo info) { try { info.Continue(); var properties = info.Request.GameProperties; this.SetTimer(properties); } catch (Exception ex) { info.Fail(this.GetType().Name + "." + MethodBase.GetCurrentMethod().Name + "():" + ex.Message); } }
public override void OnCreateGame(ICreateGameCallInfo info) { const string stripedState = "{\"LobbyId\":null,\"LobbyType\":0,\"CustomProperties\":{},\"EmptyRoomTTL\":5000,\"PlayerTTL\":2147483647,\"CheckUserOnJoin\":false,\"DeleteCacheOnLeave\":true,\"SuppressRoomEvents\":false}"; var serializableGameState = Newtonsoft.Json.JsonConvert.DeserializeObject <SerializableGameState>(stripedState); if (!this.PluginHost.SetGameState(serializableGameState)) { info.Fail("Failed to load state"); } else { info.Continue(); } }
public override void OnCreateGame(ICreateGameCallInfo info) { const string stripedState = "{\"LobbyId\":null,\"LobbyType\":0,\"CustomProperties\":{},\"EmptyRoomTTL\":5000,\"PlayerTTL\":2147483647,\"CheckUserOnJoin\":false,\"DeleteCacheOnLeave\":true,\"SuppressRoomEvents\":false}"; var serializableGameState = Newtonsoft.Json.JsonConvert.DeserializeObject<SerializableGameState>(stripedState); if (!this.PluginHost.SetGameState(serializableGameState)) { info.Fail("Failed to load state"); } else { info.Continue(); } }
public override void OnCreateGame(ICreateGameCallInfo info) { try { //before continue we expect the properties are NOT set if (this.PluginHost.GameProperties.ContainsKey("EventSize") || this.PluginHost.GameProperties.ContainsKey("Interval")) { throw new Exception("Unexpected GameProperties are already set: EventSize or Interval"); } // we check the request contains the expected game properties if (!info.Request.GameProperties.ContainsKey("EventSize") || !info.Request.GameProperties.ContainsKey("Interval")) { throw new Exception("Unexpected GameProperties are NOT set: EventSize or Interval"); } // we call explicit continue info.Continue(); // or implicit by calling the base function //base.OnCreateGame(info); // after calling continue, we expect PluginHost.GameProperties IS populated if (!this.PluginHost.GameProperties.ContainsKey("EventSize") || !this.PluginHost.GameProperties.ContainsKey("Interval")) { throw new Exception("Unexpected GameProperties are NOT set: EventSize or Interval"); } var properties = this.PluginHost.GameProperties; this.SetTimer(properties); } catch (Exception ex) { var msg = this.GetType().Name + "." + MethodBase.GetCurrentMethod().Name + "():" + ex.Message; this.PluginHost.LogError(ex); if (info.IsNew) { info.Fail(msg); } else { this.PluginHost.BroadcastErrorInfoEvent(msg); } } }
private void CreateGameCallback(IHttpResponse httpResponse, object userState) { string errorMsg; WebhooksResponse forwardResponse; ICreateGameCallInfo info = (ICreateGameCallInfo)httpResponse.CallInfo; if (!this.TryGetForwardResponse(httpResponse, out forwardResponse, out errorMsg)) { var msg = string.Format("Failed to create game on {0} : {1}", httpResponse.Request.Url, errorMsg); this.ReportError(msg); info.Fail(msg); } else { this.SuccesfullLoaded = true; info.Continue(); } }
public override void OnCreateGame(ICreateGameCallInfo info) { try { //before continue we expect the properties are NOT set if (this.PluginHost.GameProperties.ContainsKey("EventSize") || this.PluginHost.GameProperties.ContainsKey("Interval")) { throw new Exception("Unexpected GameProperties are already set: EventSize or Interval"); } // we check the request contains the expected game properties if (!info.Request.GameProperties.ContainsKey("EventSize") || !info.Request.GameProperties.ContainsKey("Interval")) { throw new Exception("Unexpected GameProperties are NOT set: EventSize or Interval"); } // we call explicit continue info.Continue(); // or implicit by calling the base function //base.OnCreateGame(info); // after calling continue, we expect PluginHost.GameProperties IS populated if (!this.PluginHost.GameProperties.ContainsKey("EventSize") || !this.PluginHost.GameProperties.ContainsKey("Interval")) { throw new Exception("Unexpected GameProperties are NOT set: EventSize or Interval"); } var properties = this.PluginHost.GameProperties; this.SetTimer(properties); } catch (Exception ex) { var msg = this.GetType().Name + "." + MethodBase.GetCurrentMethod().Name + "():" + ex.Message; this.PluginHost.LogError(ex); if(info.IsNew) info.Fail(msg); else this.PluginHost.BroadcastErrorInfoEvent(msg); } }
/// <summary> /// Calls info.Fail /// </summary> /// <param name="info"></param> public void OnCreateGame(ICreateGameCallInfo info) { info.Fail(this.errorMsg); }