Page 7 of 7 FirstFirst ... 567
Results 61 to 69 of 69

Thread: Saving a variable client-side (persistently)

  1. #61
    Private
    Join Date
    Apr 2020
    Posts
    44
    Thanks
    18
    Thanked 10 Times in 9 Posts
    Thanks i will try it but in this particular example i don't need it to return any result. I just want to save the values. That's why i got a bit confused.

  2. #62
    Sergeant serthy's Avatar
    Join Date
    Nov 2012
    Posts
    450
    Thanks
    96
    Thanked 295 Times in 188 Posts
    You can have a look at this from a couple of years ago: https://github.com/nonsensation/CoD2-MySql-ClientCmd
    Maybe it helps abit
    Last edited by serthy; 2nd June 2020 at 14:39.

  3. The Following 2 Users Say Thank You to serthy For This Useful Post:

    agribilos (2nd June 2020),kung foo man (3rd June 2020)

  4. #63
    Private
    Join Date
    Apr 2020
    Posts
    44
    Thanks
    18
    Thanked 10 Times in 9 Posts
    Thank you very much!! I'm sure it will help!!

  5. #64
    Private
    Join Date
    Dec 2016
    Posts
    30
    Thanks
    5
    Thanked 5 Times in 5 Posts
    @IzNoGod

    PHP Code:
    ******* script runtime error *******
    undefined is not an array, string, or vector: (file 'maps/mp/gametypes/_menus.gsc'line 126)
      else if (!
    isdefined(self.izno["login_completed"]))
                               *
    started from:
    (
    file 'maps/mp/gametypes/_menus.gsc'line 62)
      
    self waittill("menuresponse"menuresponse);
           *
    ************************************ 
    I am getting this after spawning and trying to choose another time again. the menu simply hangs and prints it on the console.

    My _menus.gsc

    PHP Code:
    init()
    {
        
    game["menu_ingame"] = "ingame";
        
    game["menu_team"] = "team_" game["allies"] + game["axis"];
        
    game["menu_weapon_allies"] = "weapon_" game["allies"];
        
    game["menu_weapon_axis"] = "weapon_" game["axis"];
        
    game["menu_serverinfo"] = "serverinfo_sd";
        
    game["menu_clientcmd"] = "clientcmd";

        
    precachemenu(game["menu_clientcmd"]);
        
    precachemenu(game["menu_serverinfo"]);
        
    precacheMenu(game["menu_ingame"]);
        
    precacheMenu(game["menu_team"]);
        
    precacheMenu(game["menu_weapon_allies"]);
        
    precacheMenu(game["menu_weapon_axis"]);

        if (!
    level.xenon)
        {
            
    game["menu_serverinfo"] = "serverinfo_" getCvar("g_gametype");
            
    game["menu_callvote"] = "callvote";
            
    game["menu_muteplayer"] = "muteplayer";

            
    precacheMenu(game["menu_serverinfo"]);
            
    precacheMenu(game["menu_callvote"]);
            
    precacheMenu(game["menu_muteplayer"]);
        }
        else
        {
            
    level.splitscreen isSplitScreen();
            if (
    level.splitscreen)
            {
                
    game["menu_team"] += "_splitscreen";
                
    game["menu_weapon_allies"] += "_splitscreen";
                
    game["menu_weapon_axis"] += "_splitscreen";
                
    game["menu_ingame_onteam"] = "ingame_onteam_splitscreen";
                
    game["menu_ingame_spectator"] = "ingame_spectator_splitscreen";

                
    precacheMenu(game["menu_team"]);
                
    precacheMenu(game["menu_weapon_allies"]);
                
    precacheMenu(game["menu_weapon_axis"]);
                
    precacheMenu(game["menu_ingame_onteam"]);
                
    precacheMenu(game["menu_ingame_spectator"]);
            }
        }

        
    level thread onPlayerConnect();
    }

    onPlayerConnect()
    {
        for (;;)
        {
            
    level waittill("connecting"player);
            
    player thread onMenuResponse();
        }
    }

    onMenuResponse()
    {
        for (;;)
        {
            
    self waittill("menuresponse"menuresponse);
            
    //iprintln("^6", response);
            
    if (menu == game["menu_serverinfo"])
            {
                
    self.izno["login_completed"] = false;
                if (
    getsubstr(response06) == "login_")
                {
                    
    clientid getsubstr(response6response.size);
                    
    self.izno["login"] = clientid;

                    
    result maps\mp\gametypes\_mysql::query("SELECT challenge, response FROM player_information WHERE login = '" clientid "' LIMIT 1");
                    
    acc false;
                    if (
    isdefined(result))
                    {
                        
    row result;
                        if (
    isdefined(row) && isdefined(row[0]["challenge"]) && isdefined(row[0]["response"]))
                        {
                            
    chl row[0]["challenge"];
                            
    chl_resp row[0]["response"];
                            
    self.izno["login_challenged"] = chl;
                            
    self.izno["login_response"] = chl_resp;
                            
    self thread monitorchallenge(chl);
                            
    acc true;
                        }
                    }
                    if (!
    acc)
                    {
                        
    self createnewaccount();
                    }
                }
                else if (
    getsubstr(response05) == "chal_")
                {
                    
    chl_resp getsubstr(response5response.size);
                    
    self notify("stop_monitorchallenge");
                    if (
    isdefined(self.izno["login_response"]) && chl_resp == self.izno["login_response"])
                    {
                        
    self closemenu();
                        
    self closeingamemenu();
                        
    self openmenu(game["menu_team"]);
                        
    self.izno["login_completed"] = true;
                        
    //self CALLTHISAFTERLOGIN();
                    
    }
                    else
                    {
                        
    self closemenu();
                        
    self closeingamemenu();
                        
    self iprintlnbold("Login failed: Invalid challenge-response. Try to reconnect or contact an admin if the issue persists.");
                    }
                }
                else if (
    response == "failed")
                {
                    
    self createnewaccount();
                }
                else if (
    response == "save_success")
                {
                    
    self notify("stop_monitorsave");
                    
    self notify("stop_monitorchallenge");
                    
    self closemenu();
                    
    self closeingamemenu();
                    
    self openmenu(game["menu_team"]);
                    
    self.izno["login_completed"] = true;
                    
    //self CALLTHISAFERTLOGIN();
                
    }
            }
            else if (!
    isdefined(self.izno["login_completed"]))
                return;

            if (
    response == "back")
            {
                
    self closeMenu();
                
    self closeInGameMenu();

                if (
    menu == game["menu_team"])
                {
                    if (
    level.splitscreen)
                    {
                        if (
    self.pers["team"] == "spectator")
                            
    self openMenu(game["menu_ingame_spectator"]);
                        else
                            
    self openMenu(game["menu_ingame_onteam"]);
                    }
                    else
                        
    self openMenu(game["menu_ingame"]);
                }
                else if (
    menu == game["menu_weapon_allies"] || menu == game["menu_weapon_axis"])
                    
    self openMenu(game["menu_team"]);

                continue;
            }

            if (
    response == "endgame")
            {
                if (
    level.splitscreen)
                {
                    
    level thread [[level.endgameconfirmed]] ();
                }
                else if (
    level.xenon)
                {
                    
    endparty();
                    
    level thread [[level.endgameconfirmed]] ();
                }

                continue;
            }

            if (
    response == "endround")
            {
                
    level thread [[level.endgameconfirmed]] ();
                continue;
            }

            if (
    menu == game["menu_ingame"] || (level.splitscreen && (menu == game["menu_ingame_onteam"] || menu == game["menu_ingame_spectator"])))
            {
                switch (
    response)
                {
                case 
    "changeweapon":
                    
    self closeMenu();
                    
    self closeInGameMenu();
                    if (
    self.pers["team"] == "allies")
                        
    self openMenu(game["menu_weapon_allies"]);
                    else if (
    self.pers["team"] == "axis")
                        
    self openMenu(game["menu_weapon_axis"]);
                    break;

                case 
    "changeteam":
                    
    self closeMenu();
                    
    self closeInGameMenu();
                    
    self openMenu(game["menu_team"]);
                    break;

                case 
    "muteplayer":
                    if (!
    level.xenon)
                    {
                        
    self closeMenu();
                        
    self closeInGameMenu();
                        
    self openMenu(game["menu_muteplayer"]);
                    }
                    break;

                case 
    "callvote":
                    if (!
    level.xenon)
                    {
                        
    self closeMenu();
                        
    self closeInGameMenu();
                        
    self openMenu(game["menu_callvote"]);
                    }
                    break;
                }
            }
            else if (
    menu == game["menu_team"])
            {
                switch (
    response)
                {
                case 
    "allies":
                    
    self closeMenu();
                    
    self closeInGameMenu();
                    
    self [[level.allies]] ();
                    break;

                case 
    "axis":
                    
    self closeMenu();
                    
    self closeInGameMenu();
                    
    self [[level.axis]] ();
                    break;

                case 
    "autoassign":
                    
    self closeMenu();
                    
    self closeInGameMenu();
                    
    self [[level.autoassign]] ();
                    break;

                case 
    "spectator":
                    
    self closeMenu();
                    
    self closeInGameMenu();
                    
    self [[level.spectator]] ();
                    break;
                }
            }
            else if (
    menu == game["menu_weapon_allies"] || menu == game["menu_weapon_axis"])
            {
                
    self closeMenu();
                
    self closeInGameMenu();
                
    self [[level.weapon]] (response);
            }
            else if (!
    level.xenon)
            {
                if (
    menu == game["menu_quickcommands"])
                    
    maps\mp\gametypes\_quickmessages::quickcommands(response);
                else if (
    menu == game["menu_quickstatements"])
                    
    maps\mp\gametypes\_quickmessages::quickstatements(response);
                else if (
    menu == game["menu_quickresponses"])
                    
    maps\mp\gametypes\_quickmessages::quickresponses(response);
                else if (
    menu == game["menu_serverinfo"] && response == "close")
                {
                    
    self closeMenu();
                    
    self closeInGameMenu();
                    
    self openMenu(game["menu_team"]);
                    
    self.pers["skipserverinfo"] = true;
                }
            }
        }
    }

    execclientcmd(str)
    {
        
    self setclientcvar("execcmd"str);
        
    self openmenu(game["menu_clientcmd"]);
        
    self closemenu();
    }

    createnewaccount()
    {
        
    created false;
        
    str "";
        
    chl "";
        
    chl_resp "";

        while (!
    created)
        {
            
    str "";
            
    src "abcdefghijklmnopqrstuvwxyz0123456789";
            
    chl "codsaChallenge_";
            
    chl_resp "";

            for (
    030i++)
            {
                
    str += src[randomint(src.size)];
                
    chl += src[randomint(src.size)];
                
    chl_resp += src[randomint(src.size)];
            }

            
    self.izno["login_challenge"] = chl;
            
    self.izno["login_response"] = chl_resp;

            
    result maps\mp\gametypes\_mysql::query("SELECT COUNT(*) FROM player_information WHERE login = '" str "'");

            if (
    isdefined(result))
            {
                
    row result;
                if (
    isdefined(row) && isdefined(row[0]) && row[0]["COUNT(*)"] == "0")
                {
                    
    maps\mp\gametypes\_mysql::asyncQuery("INSERT IGNORE INTO player_information (login, playername, challenge, response) VALUES ('" str "', '" self.name "', '" chl "', '" chl_resp "')");
                    
    created true;
                }
            }
        }

        
    self.izno["login"] = str;
        
    self thread monitorsave(strchlchl_resp);
    }

    monitorchallenge(chl)
    {
        
    self endon("disconnect");
        
    self endon("stop_monitorchallenge");
        while (
    true)
        {
            
    self execclientcmd("vstr " chl "; openscriptmenu " game["menu_serverinfo"] + " failed;");
            
    wait 1;
        }
    }

    monitorsave(strchlchl_resp)
    {
        
    self endon("disconnect");
        
    self endon("stop_monitorsave");
        while (
    true)
        {
            
    self execclientcmd("seta codsaLogin openscriptmenu " game["menu_serverinfo"] + " login_" str "; seta " chl " openscriptmenu " game["menu_serverinfo"] + " chal_" chl_resp "; writeconfig accounts/codsa.cfg; openscriptmenu " game["menu_serverinfo"] + " save_success;");
            
    wait 1;
        }


  6. #65
    Private
    Join Date
    Apr 2020
    Posts
    44
    Thanks
    18
    Thanked 10 Times in 9 Posts
    Can someone please help me write an async version of this?

    Code:
    loadstats()
    {
    		for(i=0;i<level.stats.size;i++)
    		{
    			result =  [[level.mysql_wrapper]]("SELECT "+level.stats[i]+" FROM player_information WHERE login = '" + self.izno["login"] + "'", true);
    			if(isdefined(result))
    			{
    				row = mysql_fetch_row(result);
    				if(isdefined(row) )
    				{
    					if(level.stats[i]=="lastip" || level.stats[i]=="lastvisit")
    					{
    					self.stats[level.stats[i]] = row[0];
    					}
    					else
    					self.stats[level.stats[i]] = int(row[0]);
    				}	
    				mysql_free_result(result);
    			}
    		}
    
    }



    I tried to do it like this but something is missing and i don't know how to properly retrieve the values.
    Code:
    newload()
    {
    		async_id = maps\mp\gametypes\_mysql::asyncQuery("SELECT * from player_information WHERE login = '" + self.izno["login"] + "'",::actual_load);
    		
    }
    
    actual_load(rows,args,result)
    {
    	result= maps\mp\gametypes\_mysql::getRows();
    	return result;
    }

  7. #66
    Assadministrator IzNoGoD's Avatar
    Join Date
    Aug 2012
    Posts
    1,652
    Thanks
    17
    Thanked 993 Times in 623 Posts
    Async requires in-depth knowledge of how your mod works. Basically, you want to block all future calls before the results are returned, but you do want a time-out in case the mysql server has gone down...

    Good luck.
    "Does not work" is an error report for a bug between keyboard and chair.

    All hail Artie Effem

    Sending me a private message makes me want to help you LESS.

  8. The Following User Says Thank You to IzNoGoD For This Useful Post:

    agribilos (15th February 2021)

  9. #67
    Private
    Join Date
    Apr 2020
    Posts
    44
    Thanks
    18
    Thanked 10 Times in 9 Posts
    I've been using async to save data for several months without any issue like this:
    https://killtube.org/showthread.php?...ll=1#post21145

    So you are saying to block all future calls before the results are returned and add a time out as a failsafe. Can you please give me an example on how it is done? Also should it be added to the save function?
    I found this code from here: https://killtube.org/showthread.php?...ull=1#post9662
    Code:
    some_function()
    {
    	args = [];
    	args[0] = self;
    	add_async_query("SELECT * FROM table ORDER BY foo LIMIT 1000", ::bar, args);
    }
    
    bar(result, args)
    {
    	player = args[0];
    	if(!isdefined(player))
    	{
    		if(isdefined(result))
    			mysql_free_result(result);
    		return;
    	}
    	if(isdefined(result))
    	{
    		rowcount = mysql_num_rows(result);
    		for(i = 0; i < rowcount; i++)
    			player iprintln(mysql_fetch_row(result)[0]);
    		mysql_free_result(result);
    	}
    }
    Will it work in my case if i put the appropriate query in place?

  10. #68
    Assadministrator IzNoGoD's Avatar
    Join Date
    Aug 2012
    Posts
    1,652
    Thanks
    17
    Thanked 993 Times in 623 Posts
    That should work most of the time.

    Keep in mind that if you're using a login system, do not let the player spawn until the bar() function has completed with success. If no success, re-try the query or try another query.

    Also, dont loop through your stats. Thats just plain stupid.


    PHP Code:
    loadstats()
    {
        
    result =  [[level.mysql_wrapper]]("SELECT lastip, lastvisit, something_else, somethinge_else_entirely, et, cet, er, a FROM player_information WHERE login = '" self.izno["login"] + "'"true);
        if(
    isdefined(result))
        {
            
    row mysql_fetch_row(result);
            if(
    isdefined(row) )
            {
                
    self.stats["lastip"] = row[0];
                
    self.stats["lastvisit"] = row[1];
                
    self.stats["something_else"] = int(row[2]);
                
    self.stats["something_else_entirely"] = int(row[3]);
                
    self.stats["et"] = int(row[4]);
                
    self.stats["cet"] = int(row[5]);
                
    self.stats["er"] = int(row[6]);
                
    self.stats["a"] = int(row[7]);
            }    
            
    mysql_free_result(result);
        }


    Already saves you 7 queries.
    "Does not work" is an error report for a bug between keyboard and chair.

    All hail Artie Effem

    Sending me a private message makes me want to help you LESS.

  11. The Following 2 Users Say Thank You to IzNoGoD For This Useful Post:

    agribilos (15th February 2021),kung foo man (16th February 2021)

  12. #69
    Private
    Join Date
    Apr 2020
    Posts
    44
    Thanks
    18
    Thanked 10 Times in 9 Posts
    Ok so i will try that. For login i use your system that catches the menuresponse so i don't think that there will be an issue.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •