Hallo,
ich habe mir selbstständig ein Login-/Register System geschrieben, jedoch macht es Probleme. (Habe seit Jahren nicht mehr gescriptet, somit etwas eingerostet)
Hier mal das ganze Script (ist noch nicht viel). Jedoch passiert nichts, sobald ich auf dem Server connecte. Kein Dialog oder ähnliches, wobei die MySQL Daten richtig sind.
/*
Copyright Copyright Copyright Copyright Copyright Copyright Copyright Copyright Copyright Copyright Copyright Copyright
Copyright Copyright Copyright Copyright Copyright Copyright Copyright Copyright Copyright Copyright Copyright
Copyright Copyright Copyright Copyright Copyright Copyright Copyright Copyright Copyright Copyright Copyright
Copyright Copyright Copyright Copyright Copyright Copyright Copyright Copyright Copyright Copyright Copyright Copyright
Ideen:
-
-
-
-
-
-
-
-
-
*/
//SA:MP Server Includes
#include <a_samp>
#include <sscanf2>
#include <a_mysql>
#include <zcmd>
//Server Informationen
#define SERVER_NAME "City of SA"
#define SERVER_HOST1 "City of SA - Reallife [0.3.7]"
#define SERVER_HOST2 "City of SA - Selfmade! [0.3.7]"
#define SERVER_MODE "Selfmade Reallife"
#define SERVER_LANG "German / Deutsch"
#define SERVER_WEB "www.city-of-sa.de"
#define SERVER_ERS "Alex"
#define SERVER_DAT "03.03.2018"
//Systematische Einstellungen
#define MAX_FRAKS 3
#define MAX_RANKS 24
//MySQL Server
#define MySQL_HOST "localhost"
#define MySQL_USER "root"
#define MySQL_PASS ""
#define MySQL_DATA "samp"
//Dialoge
enum
{
DIALOG_REGISTER,
DIALOG_LOGIN,
DIALOG_ADMINS,
DIALOG_NOTHING
}
//Serverseitige Definierungen
new MySQLConnection;
//Hinzugefügte Funktionen (Publics)
forward Load_Server();
forward MySQL_Connect();
forward Check_Player(playerid);
forward Check_Player_Step_2(playerid);
forward Register_Player(playerid);
forward Login_Player(playerid);
forward Server_Admins(playerid);
forward Load_Fraktionen();
//Speicherenumatoren
enum PlayerData
{
pID,
bool:pLogin,
pName[MAX_PLAYER_NAME],
pLevel,
pMoney,
pAdmin,
pFraktion,
pRank
}
new PlayerInfo[MAX_PLAYERS][PlayerData];
main()
{
print("======================================");
print("Das Script wurde erfolgreich geladen ("#SERVER_NAME")");
print("Ersteller: "#SERVER_ERS"");
print("Datum: "#SERVER_DAT"");
print("======================================");
}
public OnGameModeInit()
{
//Funktion (Server laden)
Load_Server();
MySQL_Connect();
AddPlayerClass(0, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0);
return 1;
}
public OnGameModeExit()
{
//MySQL Funktionen
mysql_close(MySQLConnection);
return 1;
}
public OnPlayerRequestClass(playerid, classid)
{
printf("1");
//Funktionen (Login / Registrierung)
if(!PlayerInfo[playerid][pLogin])
{
printf("2");
new query[128];
mysql_format(MySQLConnection, query, sizeof(query), "SELECT ID FROM server_accounts WHERE Name = '%e'", PlayerInfo[playerid][pName]);
mysql_function_query(MySQLConnection, query, true, "Check_Player_Step_2", "d", playerid);
printf("%s", query);
}
/*
SetPlayerPos(playerid, 1958.3783, 1343.1572, 15.3746);
SetPlayerCameraPos(playerid, 1958.3783, 1343.1572, 15.3746);
SetPlayerCameraLookAt(playerid, 1958.3783, 1343.1572, 15.3746);
*/
return 1;
}
public OnPlayerConnect(playerid)
{
//Funktionen (Login / Registrierung)
Check_Player(playerid);
return 1;
}
public OnPlayerDisconnect(playerid, reason)
{
//Funktion (Account)
Save_Player(playerid);
return 1;
}
public OnPlayerSpawn(playerid)
{
SetPlayerPos(playerid, 1485.9121,-1743.3440,13.5469);
SetPlayerFacingAngle(playerid, 2.0990);
return 1;
}
public OnPlayerDeath(playerid, killerid, reason)
{
return 1;
}
public OnVehicleSpawn(vehicleid)
{
return 1;
}
public OnVehicleDeath(vehicleid, killerid)
{
return 1;
}
public OnPlayerText(playerid, text[])
{
return 1;
}
public OnPlayerCommandText(playerid, cmdtext[])
{
if (strcmp("/mycommand", cmdtext, true, 10) == 0)
{
// Do something here
return 1;
}
return 0;
}
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
return 1;
}
public OnPlayerExitVehicle(playerid, vehicleid)
{
return 1;
}
public OnPlayerStateChange(playerid, newstate, oldstate)
{
return 1;
}
public OnPlayerEnterCheckpoint(playerid)
{
return 1;
}
public OnPlayerLeaveCheckpoint(playerid)
{
return 1;
}
public OnPlayerEnterRaceCheckpoint(playerid)
{
return 1;
}
public OnPlayerLeaveRaceCheckpoint(playerid)
{
return 1;
}
public OnRconCommand(cmd[])
{
return 1;
}
public OnPlayerRequestSpawn(playerid)
{
if(!PlayerInfo[playerid][pLogin])
{
//Funktion (Spawn ohne Registrierung / Login)
Kick(playerid);
}
return 1;
}
public OnObjectMoved(objectid)
{
return 1;
}
public OnPlayerObjectMoved(playerid, objectid)
{
return 1;
}
public OnPlayerPickUpPickup(playerid, pickupid)
{
return 1;
}
public OnVehicleMod(playerid, vehicleid, componentid)
{
return 1;
}
public OnVehiclePaintjob(playerid, vehicleid, paintjobid)
{
return 1;
}
public OnVehicleRespray(playerid, vehicleid, color1, color2)
{
return 1;
}
public OnPlayerSelectedMenuRow(playerid, row)
{
return 1;
}
public OnPlayerExitedMenu(playerid)
{
return 1;
}
public OnPlayerInteriorChange(playerid, newinteriorid, oldinteriorid)
{
return 1;
}
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
return 1;
}
public OnRconLoginAttempt(ip[], password[], success)
{
return 1;
}
public OnPlayerUpdate(playerid)
{
return 1;
}
public OnPlayerStreamIn(playerid, forplayerid)
{
return 1;
}
public OnPlayerStreamOut(playerid, forplayerid)
{
return 1;
}
public OnVehicleStreamIn(vehicleid, forplayerid)
{
return 1;
}
public OnVehicleStreamOut(vehicleid, forplayerid)
{
return 1;
}
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
switch(dialogid)
{
case DIALOG_REGISTER:
{
if(!response) return Kick(playerid);
if(strlen(inputtext) < 3) return ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, "Registrierung", "Registrierung (Text folgt)", "Registrieren", "Abbrechen");
new query[256];
mysql_format(MySQLConnection, query, sizeof(query), "INSERT INTO server_accounts (Name, Password, RegisterIP) VALUES ('%e', MD5('%e'),'%s')", PlayerInfo[playerid][pName], inputtext, GetPlayerIP(playerid));
mysql_function_query(MySQLConnection, query, true, "Register_Player", "d", playerid);
return 1;
}
case DIALOG_LOGIN:
{
if(!response) return Kick(playerid);
if(strlen(inputtext) < 3) return ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "Login", "Login (Text folgt)", "Login", "Abbrechen");
new query[256];
mysql_format(MySQLConnection, query, sizeof(query), "SELECT * FROM server_accounts WHERE Name = '%e' AND Password = MD5('%e')", PlayerInfo[playerid][pName], inputtext);
mysql_function_query(MySQLConnection, query, true, "Login_Player", "d", playerid);
}
}
return 1;
}
public OnPlayerClickPlayer(playerid, clickedplayerid, source)
{
return 1;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
public Load_Server()
{
SendRconCommand("hostname "#SERVER_HOST1"");
SendRconCommand("gamemodetext "#SERVER_MODE"");
SendRconCommand("language "#SERVER_LANG"");
SendRconCommand("weburl "#SERVER_WEB"");
}
public MySQL_Connect()
{
mysql_log(1);
print("MySQL: Die Verbindung zur Datenbank wird aufgebaut.");
MySQLConnection = mysql_connect(MySQL_HOST, MySQL_USER, MySQL_DATA, MySQL_PASS);
print("MySQL: Die Verbindung zur Datenbank wurde erfolgreich hergestellt.");
return 1;
}
public Check_Player(playerid)
{
PlayerInfo[playerid][pID] = 0;
PlayerInfo[playerid][pLogin] = false;
PlayerInfo[playerid][pLevel] = 0;
PlayerInfo[playerid][pMoney] = 0;
PlayerInfo[playerid][pAdmin] = 0;
PlayerInfo[playerid][pFraktion] = 0;
PlayerInfo[playerid][pRank] = 0;
GetPlayerName(playerid, PlayerInfo[playerid][pName], MAX_PLAYER_NAME);
return 1;
}
public Check_Player_Step_2(playerid)
{
new rows;
cache_get_row_count(rows);
if(rows == 0)
{
//Funktion (Registrierung)
ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, "Registrierung", "Registrierung (Text folgt)", "Registrieren", "Abbrechen");
}
else
{
//Funktion (Login)
ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "Login", "Login (Text folgt)", "Login", "Abbrechen");
}
return 1;
}
public Register_Player(playerid)
{
PlayerInfo[playerid][pID] = cache_insert_id();
PlayerInfo[playerid][pLogin] = true;
PlayerPlaySound(playerid, 1057 , 0.0, 0.0, 0.0);
SetPlayerScore(playerid, PlayerInfo[playerid][pLevel]);
GivePlayerMoney(playerid, PlayerInfo[playerid][pMoney]);
SpawnPlayer(playerid);
return 1;
}
public Login_Player(playerid)
{
new rows;
cache_get_row_count(rows);
if(rows == 0)
{
//Funktion (Falsches Passwort)
ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "Login", "Login (Text folgt) - Falsches Passwort", "Login", "Abbrechen");
}
else
{
//Funktion (Spieler laden)
PlayerInfo[playerid][pID] = cache_get_field_content_int(0, "ID");
PlayerInfo[playerid][pLevel] = cache_get_field_content_int(0, "Level");
PlayerInfo[playerid][pMoney] = cache_get_field_content_int(0, "Bargeld");
PlayerInfo[playerid][pAdmin] = cache_get_field_content_int(0, "Adminlevel");
PlayerInfo[playerid][pFraktion] = cache_get_field_content_int(0, "Fraktion");
PlayerInfo[playerid][pRank] = cache_get_field_content_int(0, "Rank");
PlayerInfo[playerid][pLogin] = true;
PlayerPlaySound(playerid, 1057 , 0.0, 0.0, 0.0);
GivePlayerMoney(playerid, PlayerInfo[playerid][pMoney]);
SpawnPlayer(playerid);
}
return 1;
}
stock Save_Player(playerid)
{
if(!PlayerInfo[playerid][pLogin]) return 1;
new query[256];
mysql_format(MySQLConnection, query, sizeof(query), "UPDATE server_accounts SET Level = '%d', Bargeld = '%d', Adminlevel = '%d', Fraktion = '%d', Rank = '%d' WHERE ID = '%d'",
PlayerInfo[playerid][pLevel], PlayerInfo[playerid][pMoney], PlayerInfo[playerid][pAdmin], PlayerInfo[playerid][pFraktion], PlayerInfo[playerid][pRank], PlayerInfo[playerid][pID]);
mysql_function_query(MySQLConnection, query, false, "", "");
return 1;
}
stock GetPlayerIP(playerid)
{
new IP[25];
GetPlayerIp(playerid, IP, sizeof(IP));
return IP;
}