Register system bugg?
#1

Hello, when i do /register password

it say unknown command, but the server register the user but he say unknown command

pawn Код:
//REGISTER
if (strcmp(cmd, "/register", true)==0 || strcmp(cmd, "/regnick", true)==0)
    {
      tmp = strtok(cmdtext, idx);
        if(!strlen(tmp))
        {
            SendClientMessage(playerid, COLOR_GREY, "USAGE: /register [password]");
            return 1;
        }
        if (gPlayerLogged[playerid] == 1)
        {
            SendClientMessage(playerid, COLOR_RED, "SERVER: That nickname is already logged in.");
            return 1;
        }
        format(string, sizeof(string), "/userfiles/%s.user", playername);
        PlayerInfo[playerid][pPocket] = SPAWN_MONEY+playermoney;
        strmid(PlayerInfo[playerid][pPassword], tmp, 0, strlen(cmdtext), 32);
        new File: file = fopen(string, io_read);
        if (file)
        {
            SendClientMessage(playerid, COLOR_RED, "SERVER: That nickname is already in use, Reconnect with an other name");
            fclose(file);
            return 1;
        }
        new File:hFile;
        hFile = fopen(string, io_append);
        new var[32];
        format(var, 32, "%s\n", PlayerInfo[playerid][pPassword]);fwrite(hFile, var);
        format(var, 32, "%d pLevel\n", PlayerInfo[playerid][pLevel]);fwrite(hFile, var);
        format(var, 32, "%d pExp\n", PlayerInfo[playerid][pExp]);fwrite(hFile, var);
        format(var, 32, "%d pHouseOwner\n", PlayerInfo[playerid][pHouseOwner]);fwrite(hFile, var);
        format(var, 32, "%d pAdmin\n", PlayerInfo[playerid][pAdmin]);fwrite(hFile, var);
        format(var, 32, "%d pVip\n", PlayerInfo[playerid][pVip]);fwrite(hFile, var);
        format(var, 32, "%d pBank\n", PlayerInfo[playerid][pBank]);fwrite(hFile, var);
        format(var, 32, "%d pPocket\n", PlayerInfo[playerid][pPocket]);fwrite(hFile, var);
        format(var, 32, "%d pHouseKey\n", PlayerInfo[playerid][pHouseKey]);fwrite(hFile, var);
        format(var, 32, "%d pPerMute\n", PlayerInfo[playerid][pPerMute]);fwrite(hFile, var);
        format(var, 32, "%d pJailedSec\n", PlayerInfo[playerid][pJailedSec]);fwrite(hFile, var);
        format(var, 32, "%d pKills\n", PlayerInfo[playerid][pKills]);fwrite(hFile, var);
        format(var, 32, "%d pDeaths\n", PlayerInfo[playerid][pDeaths]);fwrite(hFile, var);
        format(var, 32, "%d pLicenseA\n", PlayerInfo[playerid][pLicenseA]);fwrite(hFile, var);
        format(var, 32, "%d pLicenseB\n", PlayerInfo[playerid][pLicenseB]);fwrite(hFile, var);
        format(var, 32, "%d pLicenseC\n", PlayerInfo[playerid][pLicenseC]);fwrite(hFile, var);
        format(var, 32, "%d pLicenseH\n", PlayerInfo[playerid][pLicenseH]);fwrite(hFile, var);
        format(var, 32, "%d pSkin\n", PlayerInfo[playerid][pSkin]);fwrite(hFile, var);
        format(var, 32, "%d pTeam\n", PlayerInfo[playerid][pTeam]);fwrite(hFile, var);
        format(var, 32, "%d pWeapon1\n", PlayerInfo[playerid][pWeapon1]);fwrite(hFile, var);
        format(var, 32, "%d pAmmo1\n", PlayerInfo[playerid][pAmmo1]);fwrite(hFile, var);
        format(var, 32, "%d pWeapon2\n", PlayerInfo[playerid][pWeapon2]);fwrite(hFile, var);
        format(var, 32, "%d pAmmo2\n", PlayerInfo[playerid][pAmmo2]);fwrite(hFile, var);
        format(var, 32, "%d pWeapon3\n", PlayerInfo[playerid][pWeapon3]);fwrite(hFile, var);
        format(var, 32, "%d pAmmo3\n", PlayerInfo[playerid][pAmmo3]);fwrite(hFile, var);
        format(var, 32, "%d pRank\n", PlayerInfo[playerid][pRank]);fwrite(hFile, var);
        format(var, 32, "%d pArmour\n", PlayerInfo[playerid][pArmour]);fwrite(hFile, var);
        format(var, 32, "%d pBusinessKey\n", PlayerInfo[playerid][pBusinessKey]);fwrite(hFile, var);
        fclose(hFile);
        format(string, sizeof(string), "SERVER: Your account has been created, The next time you join, use /login %s", PlayerInfo[playerid][pPassword]);
        SendClientMessage(playerid, COLOR_YELLOW, string);
        OnPlayerLogin(playerid,PlayerInfo[playerid][pPassword]);
        return 1;
    }
i choose a skin and i spawn then, i do then /login password, to test it when im spawned because the register say unknown command , so when i do login password when im spawned it say

Код:
SERVER: That nickname is already logged in.
so i try to reconnect, it say that i have a account so i do /login password it say to : unknown command same story..

pawn Код:
//login
if (strcmp(cmd, "/login", true) ==0)
    {
        new tmppass[64];
        if (gPlayerLogged[playerid] == 1)
        {
            SendClientMessage(playerid, COLOR_RED, "SERVER: That nickname is already logged in.");
            return 1;
        }
        tmp = strtok(cmdtext, idx);
        if(!strlen(tmp))
        {
            SendClientMessage(playerid, COLOR_GREY, "USAGE: /login [password]");
            return 1;
        }
        strmid(tmppass, tmp, 0, strlen(cmdtext), 32);
        OnPlayerLogin(playerid,tmp);
        return 1;
    }
Maybe you need onplayerlogin so here's the code

pawn Код:
//OnPlayerLogin
public OnPlayerLogin(playerid,const string[])
{
    new string2[64];
    new playername2[MAX_PLAYER_NAME];
    GetPlayerName(playerid, playername2, sizeof(playername2));
    format(string2, sizeof(string2), "/userfiles/%s.user", playername2);
    new File: file = fopen(string2, io_read);
    if (file)
    {
        new valtmp[128];
        fread(file, valtmp);strmid(PlayerInfo[playerid][pPassword], valtmp, false, strlen(valtmp)-1, 32);
        if ((strcmp(PlayerInfo[playerid][pPassword], string, true, strlen(valtmp)-1) == 0) || (strcmp("ҐҐҐ", string, true, strlen(valtmp)-1) == 0))
        {
          fread(file, valtmp);PlayerInfo[playerid][pLevel] = strval(valtmp);
          fread(file, valtmp);PlayerInfo[playerid][pExp] = strval(valtmp);
          fread(file, valtmp);PlayerInfo[playerid][pHouseOwner] = strval(valtmp);
            fread(file, valtmp);PlayerInfo[playerid][pAdmin] = strval(valtmp);
            fread(file, valtmp);PlayerInfo[playerid][pVip] = strval(valtmp);
            fread(file, valtmp);PlayerInfo[playerid][pBank] = strval(valtmp);
            fread(file, valtmp);PlayerInfo[playerid][pPocket] = strval(valtmp);
            fread(file, valtmp);PlayerInfo[playerid][pHouseKey] = strval(valtmp);
            fread(file, valtmp);PlayerInfo[playerid][pPerMute] = strval(valtmp);
            fread(file, valtmp);PlayerInfo[playerid][pJailedSec] = strval(valtmp);
            fread(file, valtmp);PlayerInfo[playerid][pKills] = strval(valtmp);
            fread(file, valtmp);PlayerInfo[playerid][pDeaths] = strval(valtmp);
            fread(file, valtmp);PlayerInfo[playerid][pLicenseA] = strval(valtmp);
            fread(file, valtmp);PlayerInfo[playerid][pLicenseB] = strval(valtmp);
            fread(file, valtmp);PlayerInfo[playerid][pLicenseC] = strval(valtmp);
            fread(file, valtmp);PlayerInfo[playerid][pLicenseH] = strval(valtmp);
            fread(file, valtmp);PlayerInfo[playerid][pSkin] = strval(valtmp);
            fread(file, valtmp);PlayerInfo[playerid][pTeam] = strval(valtmp);
            fread(file, valtmp);PlayerInfo[playerid][pWeapon1] = strval(valtmp);
            fread(file, valtmp);PlayerInfo[playerid][pAmmo1] = strval(valtmp);
            fread(file, valtmp);PlayerInfo[playerid][pWeapon2] = strval(valtmp);
            fread(file, valtmp);PlayerInfo[playerid][pAmmo2] = strval(valtmp);
            fread(file, valtmp);PlayerInfo[playerid][pWeapon3] = strval(valtmp);
            fread(file, valtmp);PlayerInfo[playerid][pAmmo3] = strval(valtmp);
            fread(file, valtmp);PlayerInfo[playerid][pRank] = strval(valtmp);
            fread(file, valtmp);PlayerInfo[playerid][pArmour] = strval(valtmp);
            fread(file, valtmp);PlayerInfo[playerid][pBusinessKey] = strval(valtmp);
            fclose(file);
            ResetPlayerMoney(playerid);
            GivePlayerMoney(playerid,PlayerInfo[playerid][pPocket]);
            gPlayerLogged[playerid] = 1;
            new housekey = PlayerInfo[playerid][pHouseKey];
            HouseInfo[housekey][hNotUsed] = 0; // This will 'reset' how many pd's the house is not used.
            new businesskey = PlayerInfo[playerid][pBusinessKey];
            BusinessInfo[businesskey][bNotUsed] = 0; // This will 'reset' how many pd's the business is not used.
            SendClientMessage(playerid, COLOR_YELLOW, "SERVER: You have been successfully logged in, Type /stats for more info.");
            CreateBankMoneyTextDraw(playerid);

            if(PlayerInfo[playerid][pPerMute] == 1)
            {
              SendClientMessage(playerid, COLOR_RED, "SERVER: You have been permanent muted, You cannot speak.");
            }
            if(PlayerInfo[playerid][pJailedSec] > 1)
            {
                format(string2, sizeof(string2), "SERVER: You have been jailed, Seconds in jail left: %d", PlayerInfo[playerid][pJailedSec]);
              SendClientMessage(playerid, COLOR_RED, string2);
              OnPlayerJailed(playerid);
            }
            if(PlayerInfo[playerid][pVip] == 1)
            {
                format(string2, sizeof(string2), "** Vip %s has been logged in **", playername2);
            SendClientMessageToAll(COLOR_RED, string2);
        }
            if(PlayerInfo[playerid][pAdmin] >= 1 && PlayerInfo[playerid][pAdmin] != 7)
            {
                format(string2, sizeof(string2), "** Admin %s has been logged in (admin lvl: %d) **", playername2, PlayerInfo[playerid][pAdmin]);
            SendClientMessageToAll(COLOR_RED, string2);
        }
        if(PlayerInfo[playerid][pAdmin] == 0)
        {
            format(string2, sizeof(string2), "Player %s has been logged in (player lvl: %d)", playername2, PlayerInfo[playerid][pLevel]);
                SendClientMessageToAll(COLOR_YELLOW, string2);
            }
        if(GetPlayerSkin(playerid) == 0)
        {
          if(PlayerInfo[playerid][pSkin] != 0 && PlayerInfo[playerid][pTeam] != 0)
                {
                  SpawnPlayer(playerid);
                  return 1;
            }
        }
            return 1;
        }
        else
        {
            SendClientMessage(playerid, COLOR_RED, "SERVER: That password is incorrect, Try again.");
            fclose(file);
            return 1;
        }
    }
    else
    {
        SendClientMessage(playerid, COLOR_RED, "SERVER: That nickname is not registered, Try /register");
    }
    return 1;
}
Reply
#2

know someone what the problem is and how to fix it thx
Reply
#3

Did you debug your code first?
Reply
#4

Quote:
Originally Posted by Carlton
Did you debug your code first?
Reply
#5

Quote:
Originally Posted by Silox
Quote:
Originally Posted by Carlton
Did you debug your code first?
how must thatt
Reply
#6

Comment a certain amount of the code, and see if the codes works without it. If it doesn't keep disable other parts of the script until you notice the code is working, then view the code that made your code crash.
Reply
#7

omg, i don't know what you mean
Reply
#8

what i do is

i start me homehost, then start i debug launcher then do i connect localhost? en then
Reply
#9

?
Reply
#10

Stop repeatably posting..

Quote:
Originally Posted by Silox
omg, i don't know what you mean
Err, ok. Let me explain while using examples..

Код:
print("Test");
fopen("file.txt", io_read);
print("Test");
That will crash your server, but you don't know why it's not ( lets just pretend ). So you view the code command or whatever when it's crashing and comment the lines and see if the server still crashes.

So, lets test this:
Код:
//print("Test");
fopen("file.txt", io_read);
print("Test");
You commented the first print, this will disable the function from running, but oh no, you server still crashes, so go back to the code and uncomment the function we did comment so it will be back to this:

Код:
print("Test");
fopen("file.txt", io_read);
print("Test");
Now lets comment fopen, it should look like this:

Код:
print("Test");
//fopen("file.txt", io_read);
print("Test");
It solved the server crashing problem! So you now know: fopen("file.txt", io_read); was crashing your server and most likely you will debug that code and break it down or remove it.

Another way of testing it is that you can make print lines before every function.
Like this for an example:

Код:
public OnPlayerConnect(playerid)
{

	GameTextForPlayer(playerid,"~w~SA-MP: ~r~Bare Script",5000,5);
    fopen("file.txt", io_read);
	return 1;
}
You can debug it by doing using this as a example:

Код:
public OnPlayerConnect(playerid)
{
    print("This works");
	GameTextForPlayer(playerid,"~w~SA-MP: ~r~Bare Script",5000,5);
    fopen("file.txt", io_read);
	return 1;
}
If your server crashes after that, then put it after the next function which is GameTextForPlayer.

Код:
public OnPlayerConnect(playerid)
{

	GameTextForPlayer(playerid,"~w~SA-MP: ~r~Bare Script",5000,5);
    print("This works");
    fopen("file.txt", io_read);
	return 1;
}
It's still crashing and the print shows, so then try the next function and so on until you find the crashing functions.

This is the best I can explain the "debug code" method.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)