Пример #1
0
        public override void OnRaiseEvent(IRaiseEventCallInfo info)
        {
            switch (info.Request.EvCode)
            {
            case 0:    // all good
            {
                var request = new HttpRequest
                {
                    Async    = true,
                    Callback = HttpCallback,
                    Url      = "https://wt-e4c18d407aa73a40e4182aaf00a2a2eb-0.run.webtask.io/auth/auth-demo/",
                };

                this.PluginHost.HttpRequest(request, null);
                info.Continue();
            }
            break;

            case 1:    // no continue call
            {
                var request = new HttpRequest
                {
                    Async    = true,
                    Callback = HttpCallback,
                    Url      = "https://wt-e4c18d407aa73a40e4182aaf00a2a2eb-0.run.webtask.io/auth/auth-demo/",
                };

                this.PluginHost.HttpRequest(request, null);
            }
            break;

            case 2:    // sync call
            {
                var request = new HttpRequest
                {
                    Async    = false,
                    Callback = HttpCallback,
                    Url      = "https://wt-e4c18d407aa73a40e4182aaf00a2a2eb-0.run.webtask.io/auth/auth-demo/",
                };

                this.PluginHost.HttpRequest(request, null);
                info.Continue();
            }
            break;

            default:
                base.OnRaiseEvent(info);
                break;
            }
        }
Пример #2
0
        public override void OnRaiseEvent(IRaiseEventCallInfo info)
        {
            if (info.Request.EvCode == 0)
            {
                base.OnRaiseEvent(info);
            }
            else if (info.Request.EvCode == 1)
            {
                info.Defer();
            }
            else if (info.Request.EvCode == 2)
            {
                info.Cancel();
            }
            else if (info.Request.EvCode == 3)
            {
                info.Fail();
                this.PluginHost.BroadcastErrorInfoEvent("We called fail method");
            }
            else if (info.Request.EvCode == 4)
            {
                throw new Exception("Event 4 exception");
            }
            else if (info.Request.EvCode == 5)
            {
                var request = new HttpRequest
                {
                    Async    = true,
                    Callback = HttpCallbackWithException,
                    Url      = "http://photon.webscript.io/auth-demo/",
                };

                this.PluginHost.HttpRequest(request);
                info.Defer();
            }
            else if (info.Request.EvCode == 6)
            {
                var request = new HttpRequest
                {
                    Async    = false,
                    Callback = HttpCallbackWithException,
                    Url      = "http://photon.webscript.io/auth-demo/",
                };

                this.PluginHost.HttpRequest(request);
                info.Continue();
            }
            else if (info.Request.EvCode == 7)
            {
                this.timer = this.PluginHost.CreateOneTimeTimer(this.TimerAction, 100);
                info.Defer();
            }
            else if (info.Request.EvCode == 8)
            {
                this.timer = this.PluginHost.CreateTimer(this.TimerAction, 100, 100);
                info.Defer();
            }
        }
        /// <summary>
        /// Callback for recived events
        /// </summary>
        /// <param name="info"></param>
        public override void OnRaiseEvent(IRaiseEventCallInfo info)
        {
            switch ((Event)info.Request.EvCode)
            {
            case Event.Move:
                OnOpen(info);
                info.Continue();
                break;

            case Event.ToggleFlag:
                OnToggleFlag(info);
                info.Continue();
                break;

            default:
                info.Cancel();
                break;
            }
        }
Пример #4
0
        void Fire(IRaiseEventCallInfo info)
        {
            var ammo = (int)GetActor(info.ActorNr).Properties.GetProperty("Ammo").Value;

            if (ammo <= 0)
            {
                this.PluginHost.LogError("Fire failed for player " + info.ActorNr);
                info.Fail("No ammo available");
            }
            else
            {
                SetAmmo(info.ActorNr, ammo - 1);
                info.Continue();
            }
        }
 public override void OnRaiseEvent(IRaiseEventCallInfo info)
 {
     this.DoHttpCall(info, (response, state) =>
     {
         this.PluginHost.LogDebug("Executing http callback for OnRaiseEvent");
         this.PluginHost.CreateOneTimeTimer(info, () =>
         {
             this.PluginHost.LogDebug("Executing timer callback for OnRaiseEvent");
             if (!this.noCallback)
             {
                 info.Continue();
             }
             this.BroadcastEvent(123, null);
         }, 1000);
     });
 }
Пример #6
0
 public override void OnRaiseEvent(IRaiseEventCallInfo info)
 {
     if (info.Request.EvCode != 3)
     {
         var request = new HttpRequest
         {
             Async    = info.Request.EvCode == 1,
             Url      = "https://wt-e4c18d407aa73a40e4182aaf00a2a2eb-0.run.webtask.io/realtime-webhooks-1.2/GameEvent",
             Callback = this.HttpRequestCallback,
         };
         // just to give next event time to reach plugin
         Thread.Sleep(100);
         this.PluginHost.HttpRequest(request, info);
     }
     else
     {
         this.PluginHost.BroadcastEvent(ReciverGroup.All, 0, 0, info.Request.EvCode, null, 0);
         info.Continue();
     }
 }
Пример #7
0
        public override void OnRaiseEvent(IRaiseEventCallInfo info)
        {
            switch (info.Request.EvCode)
            {
            case 0:    // all good
            {
                this.PluginHost.CreateOneTimeTimer(null, () => { }, 10);
                info.Continue();
            }
            break;

            case 1:    // no continue call
            {
                this.PluginHost.CreateOneTimeTimer(null, () => { }, 10);
            }
            break;

            default:
                base.OnRaiseEvent(info);
                break;
            }
        }
Пример #8
0
 public override void OnRaiseEvent(IRaiseEventCallInfo info)
 {
     this.onRaiseEvent.Set();
     info.Continue();
 }
Пример #9
0
 /// <summary>
 /// Calls info.Continue(). Override to change.
 /// </summary>
 /// <param name="info">Data passed in the callback call.</param>
 public virtual void OnRaiseEvent(IRaiseEventCallInfo info)
 {
     info.Continue();
 }
Пример #10
0
 public override void OnRaiseEvent(IRaiseEventCallInfo info)
 {
     this.onRaiseEvent.Set();
     info.Continue();
 }
        public override void OnRaiseEvent(IRaiseEventCallInfo info)
        {
            if (info.Request.EvCode == 0)
            {
                base.OnRaiseEvent(info);
            }
            else if (info.Request.EvCode == 1)
            {
                info.Defer();
            }
            else if (info.Request.EvCode == 2)
            {
                info.Cancel();
            }
            else if (info.Request.EvCode == 3)
            {
                info.Fail();
                this.PluginHost.BroadcastErrorInfoEvent("We called fail method");
            }
            else if (info.Request.EvCode == 4)
            {
                throw new Exception("Event 4 exception");
            }
            else if (info.Request.EvCode == 5)
            {
                var request = new HttpRequest
                {
                    Async = true,
                    Callback = HttpCallbackWithException,
                    Url = "http://photon.webscript.io/auth-demo/",
                };

                this.PluginHost.HttpRequest(request);
                info.Defer();
            }
            else if (info.Request.EvCode == 6)
            {
                var request = new HttpRequest
                {
                    Async = false,
                    Callback = HttpCallbackWithException,
                    Url = "http://photon.webscript.io/auth-demo/",
                };

                this.PluginHost.HttpRequest(request);
                info.Continue();
            }
            else if (info.Request.EvCode == 7)
            {
                this.timer = this.PluginHost.CreateOneTimeTimer(this.TimerAction, 100);
                info.Defer();
            }
            else if (info.Request.EvCode == 8)
            {
                this.timer = this.PluginHost.CreateTimer(this.TimerAction, 100, 100);
                info.Defer();
            }
        }
        public override void OnRaiseEvent(IRaiseEventCallInfo info)
        {
            string ReturnMessage = "";

            // Login System
            if (info.Request.EvCode == 1)
            {
                RecvdMessage = Encoding.Default.GetString((byte[])info.Request.Data);
                string playerName     = GetStringDataFromMessage("PlayerName");
                string playerPassword = GetStringDataFromMessage("Password");

                string          search_sql = "SELECT name, password FROM users WHERE name = '" + playerName + "'";
                MySqlCommand    cmd        = new MySqlCommand(search_sql, conn);
                MySqlDataReader rdr        = cmd.ExecuteReader();

                if (rdr.HasRows)
                {
                    while (rdr.Read())
                    {
                        // playerPassword does not match with the password in database, UPDATE the password in database
                        if (!rdr[1].Equals(playerPassword))
                        {
                            // Close Select Operation before start Update Operation
                            rdr.Close();
                            string update_sql = "UPDATE users SET password = '******' WHERE name = '" + playerName + "'";
                            cmd.CommandText = update_sql;
                            cmd.ExecuteNonQuery();

                            ReturnMessage = playerName + " - LoginResult=PasswordUpdated";

                            // Need to break since already Close reader, can no longer access reader.Read()
                            break;
                        }
                        // playerPassword match with the password in database - worked
                        else
                        {
                            rdr.Close();
                            ReturnMessage = playerName + " - LoginResult=OK";
                            break;
                        }
                    }
                }
                // playerName does not exist in database, INSERT into database
                else
                {
                    // Close Select Operation before start Insert Operation
                    rdr.Close();
                    string insert_sql = "INSERT INTO users (name, password, date_created) VALUES ('" + playerName + "', '" + playerPassword + "', now())";
                    cmd.CommandText = insert_sql;
                    cmd.ExecuteNonQuery();

                    ReturnMessage = playerName + " - LoginResult=NewUser";
                }

                BroadcastEvent(info, ReturnMessage);
            }
            // Read position from DB
            else if (info.Request.EvCode == 2)
            {
                RecvdMessage = Encoding.Default.GetString((byte[])info.Request.Data);
                string playerName = GetStringDataFromMessage("PlayerName");

                string          search_sql = "SELECT name, PlayerX, PlayerY, PlayerZ, PetX, PetY, PetZ FROM users WHERE name = '" + playerName + "'";
                MySqlCommand    cmd        = new MySqlCommand(search_sql, conn);
                MySqlDataReader rdr        = cmd.ExecuteReader();

                if (rdr.HasRows)
                {
                    while (rdr.Read())
                    {
                        // all x,y,z are not null, send the value from DB to client
                        if (!DBNull.Value.Equals(rdr[1]) && !DBNull.Value.Equals(rdr[2]) && !DBNull.Value.Equals(rdr[3]) &&
                            !DBNull.Value.Equals(rdr[4]) && !DBNull.Value.Equals(rdr[5]) && !DBNull.Value.Equals(rdr[6]))
                        {
                            ReturnMessage = playerName + " - Result=NotNull, - PlayerX=" + rdr[1].ToString() +
                                            ", PlayerY=" + rdr[2].ToString() + ", PlayerZ=" + rdr[3].ToString() +

                                            ", PetX=" + rdr[4].ToString() + ", PetY=" + rdr[5].ToString() +
                                            ", PetZ=" + rdr[6].ToString();

                            // Close Select Operation
                            rdr.Close();

                            // Need to break since already Close reader, can no longer access reader.Read()
                            break;
                        }
                        // one/all of x,y,z is/are null, tell client to load default position instead
                        else
                        {
                            rdr.Close();
                            ReturnMessage = playerName + " - Result=Null";
                            break;
                        }
                    }
                }
                // playerName does not exist in database
                else
                {
                    // Close Select Operation
                    rdr.Close();
                }

                SendEvent(info, ReturnMessage, new List <int> {
                    info.ActorNr
                });

                // prevent raiseevent from being sent to all players
                info.Cancel();
            }
            // Update position in DB
            else if (info.Request.EvCode == 3)
            {
                RecvdMessage = Encoding.Default.GetString((byte[])info.Request.Data);
                string playerName = GetStringDataFromMessage("PlayerName");
                string playerX    = GetStringDataFromMessage("PlayerX");
                string playerY    = GetStringDataFromMessage("PlayerY");
                string playerZ    = GetStringDataFromMessage("PlayerZ");
                string petX       = GetStringDataFromMessage("PetX");
                string petY       = GetStringDataFromMessage("PetY");
                string petZ       = GetStringDataFromMessage("PetZ");

                string update_sql = "UPDATE users SET PlayerX = '" + playerX + "', PlayerY = '" + playerY + "', PlayerZ = '" + playerZ
                                    + "', PetX = '" + petX + "', PetY = '" + petY + "', PetZ = '" + petZ + "' WHERE name = '" + playerName + "'";
                MySqlCommand cmd = new MySqlCommand(update_sql, conn);
                cmd.ExecuteNonQuery();

                ReturnMessage = playerName + " - Result=PositionUpdated";

                BroadcastEvent(info, ReturnMessage);
            }
            //Receive & broadcast the attacking player's name and their position
            else if (info.Request.EvCode == 4)
            {
                RecvdMessage = Encoding.Default.GetString((byte[])info.Request.Data);
                string playerName = GetStringDataFromMessage("PlayerName");
                string playerX    = GetStringDataFromMessage("X");
                string playerY    = GetStringDataFromMessage("Y");
                string playerZ    = GetStringDataFromMessage("Z");

                ReturnMessage = "Player=" + playerName + " attacked (" + playerX + ',' + playerY + ',' + playerZ + ')';

                BroadcastEvent(info, ReturnMessage);
            }
            //Receive & broadcast which player is defending or has stoppped defending
            else if (info.Request.EvCode == 5)
            {
                RecvdMessage = Encoding.Default.GetString((byte[])info.Request.Data);
                string playerName = GetStringDataFromMessage("PlayerName");

                if (RecvdMessage.Last() == '1')
                {
                    ReturnMessage = "Player " + playerName + " is currently DEFENDING";
                }
                else
                {
                    ReturnMessage = "Player " + playerName + " has STOPPED DEFENDING";
                }

                BroadcastEvent(info, ReturnMessage);
            }

            info.Continue();
        }
Пример #13
0
        public override void OnRaiseEvent(IRaiseEventCallInfo info)
        {
            if (info.Request.EvCode == 0)
            {
                base.OnRaiseEvent(info);
            }
            else if (info.Request.EvCode == 1)
            {
#pragma warning disable CS0618 // Type or member is obsolete
                info.Defer();
#pragma warning restore CS0618 // Type or member is obsolete
            }
            else if (info.Request.EvCode == 2)
            {
                info.Cancel();
            }
            else if (info.Request.EvCode == 3)
            {
                info.Fail();
                this.PluginHost.BroadcastErrorInfoEvent("We called fail method");
            }
            else if (info.Request.EvCode == 4)
            {
                throw new Exception("Event 4 exception");
            }
            else if (info.Request.EvCode == 5)
            {
                var request = new HttpRequest
                {
                    Async    = true,
                    Callback = HttpCallbackWithException,
                    Url      = "https://wt-e4c18d407aa73a40e4182aaf00a2a2eb-0.run.webtask.io/auth/auth-demo/",
                };

#pragma warning disable CS0612 // Type or member is obsolete
                this.PluginHost.HttpRequest(request);
#pragma warning restore CS0612 // Type or member is obsolete
#pragma warning disable CS0618 // Type or member is obsolete
                info.Defer();
#pragma warning restore CS0618 // Type or member is obsolete
            }
            else if (info.Request.EvCode == 6)
            {
                var request = new HttpRequest
                {
                    Async    = false,
                    Callback = HttpCallbackWithException,
                    Url      = "https://wt-e4c18d407aa73a40e4182aaf00a2a2eb-0.run.webtask.io/auth/auth-demo/",
                };

#pragma warning disable CS0612 // Type or member is obsolete
                this.PluginHost.HttpRequest(request);
#pragma warning restore CS0612 // Type or member is obsolete
                info.Continue();
            }
            else if (info.Request.EvCode == 7)
            {
#pragma warning disable CS0612 // Type or member is obsolete
                this.timer = this.PluginHost.CreateOneTimeTimer(this.TimerAction, 100);
#pragma warning restore CS0612 // Type or member is obsolete
#pragma warning disable CS0618 // Type or member is obsolete
                info.Defer();
#pragma warning restore CS0618 // Type or member is obsolete
            }
            else if (info.Request.EvCode == 8)
            {
                this.timer = this.PluginHost.CreateTimer(this.TimerAction, 100, 100);
#pragma warning disable CS0618 // Type or member is obsolete
                info.Defer();
#pragma warning restore CS0618 // Type or member is obsolete
            }
        }
Пример #14
0
 /// <summary>
 /// Calls info.Continue(). Override to change.
 /// </summary>
 /// <param name="info">Data passed in the callback call.</param>
 public virtual void OnRaiseEvent(IRaiseEventCallInfo info)
 {
     info.Continue();
 }