コード例 #1
0
        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);
            }
        }
コード例 #2
0
        /// <summary>
        /// Callback when room is created
        /// </summary>
        /// <param name="info"></param>
        public override void OnCreateGame(ICreateGameCallInfo info)
        {
            this.PluginHost.LogInfo(string.Format("OnCreateGame {0} by user {1}", info.Request.GameId, info.UserId));
            info.Continue(); // same as base.OnCreateGame(info);

            System.Collections.Hashtable hashtable = info.OperationRequest.Parameters[248] as System.Collections.Hashtable;

            int hight = (int)hashtable["hight"];
            int width = (int)hashtable["width"];

            NumberOfPlayers = (int)hashtable["maxPlayers"];
            firstSafe       = (bool)hashtable["firstSafe"];
            endOnExpload    = (bool)hashtable["endOnExpload"];
            joinAfterStart  = (bool)hashtable["joinAfter"];



            float mineRate = 0.1f;

            if (hashtable.ContainsKey("mineRate"))
            {
                mineRate = (float)(int)hashtable["mineRate"] / 100;
            }
            int mineCount = (int)(hight * width * mineRate);

            board = new Board(hight, width, mineCount);



            this.PluginHost.LogInfo(string.Format("GameCreated {0} by {1} with {2} mines. FirstSafe {3}, endOnExpload {4}, JoinAfterStart {5}", hight, width, board.MineCount, firstSafe, endOnExpload, joinAfterStart));
        }
コード例 #3
0
 public override void OnCreateGame(ICreateGameCallInfo info)
 {
     this.SetupPlugin(info);
     if (this.doSyncHttpAndTimer)
     {
         info.Continue();
         return;
     }
     this.MethodBody(info, MethodBase.GetCurrentMethod().Name);
 }
コード例 #4
0
ファイル: TestExtra.cs プロジェクト: cernysw/UnityDemo
        public override void OnCreateGame(ICreateGameCallInfo info)
        {
            this.onCreateEvent.Set();

            if (this.PluginHost.GameId.EndsWith("OnCreateForgotCall"))
            {
                return;
            }

            info.Continue();
        }
コード例 #5
0
        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);
            }
        }
コード例 #6
0
        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);
            }
        }
コード例 #7
0
        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();
            }
        }
コード例 #8
0
        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();
            }
        }
コード例 #9
0
        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);
                }
            }
        }
コード例 #10
0
        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();
            }
        }
コード例 #11
0
        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);
            }
        }
コード例 #12
0
ファイル: TestExtra.cs プロジェクト: JerryBian/PhotonSample
        public override void OnCreateGame(ICreateGameCallInfo info)
        {
            this.onCreateEvent.Set();

            if (this.PluginHost.GameId.EndsWith("OnCreateForgotCall"))
            {
                return;
            }

            info.Continue();
        }
コード例 #13
0
ファイル: PluginBase.cs プロジェクト: theGameShop/Flipper
 /// <summary>
 /// Calls info.Continue(). Override to change.
 /// </summary>
 /// <param name="info">Data passed in the callback call.</param>
 public virtual void OnCreateGame(ICreateGameCallInfo info)
 {
     System.Diagnostics.Debug.Assert(this.PluginHost != null);
     info.Continue();
 }
コード例 #14
0
        public override void OnCreateGame(ICreateGameCallInfo info)
        {
            if (!info.IsJoin)
            {
                var url = this.gameCreatedUrl;
                if (this.IsPersistent)
                {
                    this.PostJsonRequest(
                        url,
                        new WebhooksRequest
                        {
                            Type = "Create",
                            GameId = this.PluginHost.GameId,
                            AppId = this.AppId,
                            AppVersion = this.AppVersion,
                            Region = this.Region,
                            UserId = info.UserId,
                            Nickname = info.Nickname,
                            ActorNr = 1,
                            CreateOptions = info.CreateOptions,
                            AuthCookie = info.AuthCookie,
                        },
                        this.CreateGameCallback,
                        info,
                        callAsync: false);
                }
                else
                {
                    if (!string.IsNullOrEmpty(url))
                    {
                        this.PostJsonRequest(
                            url,
                            new WebhooksRequest
                            {
                                Type = "Create",
                                GameId = this.PluginHost.GameId,
                                AppId = this.AppId,
                                AppVersion = this.AppVersion,
                                Region = this.Region,
                                UserId = info.UserId,
                                Nickname = info.Nickname,
                                ActorNr = 1,
                                CreateOptions = info.CreateOptions,
                                AuthCookie = info.AuthCookie,
                            },
                            this.LogIfFailedCallback,
                            info,
                            callAsync: true);
                    }

                    this.SuccesfullLoaded = true;
                    info.Continue();
                }
            }
            else
            {
                this.PluginHost.LogDebug("OnCreateGame: Loading");

                if (this.IsPersistent)
                {
                    var url = !string.IsNullOrEmpty(this.gameLoadUrl) ? this.gameLoadUrl : this.gameCreatedUrl;

                    this.PluginHost.LogDebug(string.Format(
                        "OnCreateGame: sending http load game request: url={0} gameid={1} userid={2}",
                        this.gameLoadUrl,
                        this.PluginHost.GameId,
                        info.UserId));

                    this.PostJsonRequest(
                        url,
                        new WebhooksRequest
                        {
                            Type = "Load",
                            GameId = this.PluginHost.GameId,
                            AppId = this.AppId,
                            AppVersion = this.AppVersion,
                            Region = this.Region,
                            UserId = info.UserId,
                            Nickname = info.Nickname,
                            ActorNr = info.Request.ActorNr,
                            CreateIfNotExists = info.CreateIfNotExists,
                            CreateOptions = info.CreateOptions,
                            AuthCookie = info.AuthCookie,
                        },
                        this.LoadCallback,
                        info,
                        callAsync: false);
                }
                else
                {
                    if (!info.CreateIfNotExists)
                    {
                        //TBD: thsi should never be called, maybe we should move this to base plugin
                        throw new Exception("Join/Rejoin: missing CreateIfNotExists.");
                    }

                    this.SuccesfullLoaded = true;
                    info.Continue();
                }
            }
        }
コード例 #15
0
        public override void OnCreateGame(ICreateGameCallInfo info)
        {
            if (!info.IsJoin)
            {
                var url = this.gameCreatedUrl;
                if (this.IsPersistent)
                {
                    this.PostJsonRequest(
                        url,
                        new WebhooksRequest
                    {
                        Type          = "Create",
                        GameId        = this.PluginHost.GameId,
                        AppId         = this.AppId,
                        AppVersion    = this.AppVersion,
                        Region        = this.Region,
                        UserId        = info.UserId,
                        Nickname      = info.Nickname,
                        ActorNr       = 1,
                        CreateOptions = info.CreateOptions,
                        AuthCookie    = info.AuthCookie,
                    },
                        this.CreateGameCallback,
                        info,
                        callAsync: false);
                }
                else
                {
                    if (!string.IsNullOrEmpty(url))
                    {
                        this.PostJsonRequest(
                            url,
                            new WebhooksRequest
                        {
                            Type          = "Create",
                            GameId        = this.PluginHost.GameId,
                            AppId         = this.AppId,
                            AppVersion    = this.AppVersion,
                            Region        = this.Region,
                            UserId        = info.UserId,
                            Nickname      = info.Nickname,
                            ActorNr       = 1,
                            CreateOptions = info.CreateOptions,
                            AuthCookie    = info.AuthCookie,
                        },
                            this.LogIfFailedCallback,
                            info,
                            callAsync: true);
                    }

                    this.SuccesfullLoaded = true;
                    info.Continue();
                }
            }
            else
            {
                this.PluginHost.LogDebug("OnCreateGame: Loading");

                if (this.IsPersistent)
                {
                    var url = !string.IsNullOrEmpty(this.gameLoadUrl) ? this.gameLoadUrl : this.gameCreatedUrl;

                    this.PluginHost.LogDebug(string.Format(
                                                 "OnCreateGame: sending http load game request: url={0} gameid={1} userid={2}",
                                                 this.gameLoadUrl,
                                                 this.PluginHost.GameId,
                                                 info.UserId));

                    this.PostJsonRequest(
                        url,
                        new WebhooksRequest
                    {
                        Type              = "Load",
                        GameId            = this.PluginHost.GameId,
                        AppId             = this.AppId,
                        AppVersion        = this.AppVersion,
                        Region            = this.Region,
                        UserId            = info.UserId,
                        Nickname          = info.Nickname,
                        ActorNr           = info.Request.ActorNr,
                        CreateIfNotExists = info.CreateIfNotExists,
                        CreateOptions     = info.CreateOptions,
                        AuthCookie        = info.AuthCookie,
                    },
                        this.LoadCallback,
                        info,
                        callAsync: false);
                }
                else
                {
                    if (!info.CreateIfNotExists)
                    {
                        //TBD: thsi should never be called, maybe we should move this to base plugin
                        throw new Exception("Join/Rejoin: missing CreateIfNotExists.");
                    }

                    this.SuccesfullLoaded = true;
                    info.Continue();
                }
            }
        }
コード例 #16
0
 public override void OnCreateGame(ICreateGameCallInfo info)
 {
     this.PluginHost.LogInfo($"OnCreateGame {info.Request.GameId} by user {info.UserId}");
     info.Continue();
 }
コード例 #17
0
ファイル: PluginBase.cs プロジェクト: JerryBian/PhotonSample
 /// <summary>
 /// Calls info.Continue(). Override to change.
 /// </summary>
 /// <param name="info">Data passed in the callback call.</param>
 public virtual void OnCreateGame(ICreateGameCallInfo info)
 {
     System.Diagnostics.Debug.Assert(this.PluginHost != null);
     info.Continue();
 }