Beispiel #1
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();
            }
        }
        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/",
                };

                this.PluginHost.HttpRequest(request, info);
            }
            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/",
                };

                this.PluginHost.HttpRequest(request, info);
            }
            else if (info.Request.EvCode == 7)
            {
                this.timer = this.PluginHost.CreateOneTimeTimer(info, this.TimerAction, 100);
            }
            else if (info.Request.EvCode == 8)
            {
                this.timer = this.PluginHost.CreateTimer(this.TimerAction, 100, 100);
            }
        }
        /// <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;
            }
        }
        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();
        }