AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Suggestions / Requests (https://forums.alliedmods.net/forumdisplay.php?f=12)
-   -   Change Name (with SQL) (https://forums.alliedmods.net/showthread.php?t=116278)

spiider 01-21-2010 16:09

Change Name (with SQL)
 
Hi.
Some one can help me code a script for search in MySQL db for user steamid and then change user name for the name in database.

spiider 03-15-2010 11:53

Re: Change Name (with SQL)
 
Here is the code maybe help someone.
I'm now with a problem every time change map my plugin say can't connect to database and i don't change anything in plugin.

PHP Code:

/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <amxmisc>
#include <dbi>
#include <engine>
#include <csx>

#define PLUGIN "Change Name and Kick no registered steamID"
#define VERSION "1.0"
#define AUTHOR "spiider"


#define CVAR_CHHOST            "reg_host"
#define CVAR_CHUSER            "reg_user"
#define CVAR_CHPASS            "reg_pass"
#define CVAR_CHDB            "reg_db"
#define TABLE                "users"


//new names[32] // id->playername
new g_regged[33]
// vars going here
new gate_matchID
//public pug_cvar_shield = 1;

public plugin_modules() {
    
require_module("engine")
    
require_module("dbi")
}

// here goes check client and change name :)

public client_authorized(id) {
    if (
is_user_bot(id))
        return 
PLUGIN_CONTINUE
    
    
new authid[32]
    
get_user_authid(id,authid,31)
    new 
Sql:sql
    
if (!connect(sql))
        return 
false
    
    
const LONGER 128
    
new query[LONGER 1]
    
    
format(queryLONGER"SELECT `name` FROM %s WHERE `steamid` = '%s' LIMIT 1"TABLEauthid)
    new 
Result:result dbi_query(sqlquery)
    
    
    
//Loop through the result set   
    
while (result && dbi_nextrow(result)>0) {
        new 
qry[32]
        
//Get the column/field called "keyname" from the result set
        
dbi_result(result"name"qry32)
        
set_user_info(id,"name",qry)
        
    }
    
    
dbi_close(sql)
    
    
    
g_regged[id] = checkregister(authid)
    
    if (
g_regged[id]) {
        
        } else {
        
server_cmd("kick #%d Your steamID %s is not registered for this game."get_user_userid(id), authid)
    }
    
    
    
    
    return 
true
}

// now when change name in game
public client_infochanged(id) {
    if (
is_user_bot(id) || is_user_connecting(id))
        return 
PLUGIN_CONTINUE
    
new nick[32]
    new 
newnick[32]
    new 
authid[32]
    
get_user_authid(id,authid,31)
    new 
Sql:sql
    
if (!connect(sql))
        return 
false
    
    
const LONGER 128
    
new query[LONGER 1]
    
    
format(queryLONGER"SELECT `name` FROM %s WHERE `steamid` = '%s' LIMIT 1"TABLEauthid)
    new 
Result:result dbi_query(sqlquery)
    
    
    
//Loop through the result set   
    
while (result && dbi_nextrow(result)>0) {
        new 
qry[32]
        
dbi_result(result"name"qry32)
        
// set_user_info(id,"name",qry)
        
nick qry;
    }
    
    
    
format(newnick31"%s"nick)
    
set_user_info(id"name"newnick)
    
    
dbi_close(sql)
    
    return 
true
}
// here goes check if is registered for this game
bool:checkregister(authid[]) {
    new 
Sql:sql
    
if (!connect(sql))
        return 
false
    
const LONGER 128
    
new query[LONGER 1]
    
gate_matchID get_cvar_pointer "matchID" )
    
format(queryLONGER"SELECT `playerID` FROM players WHERE `steamID` = ^"%s^" AND `matchID` = '%d' LIMIT 1"authid,get_pcvar_num(gate_matchID))
    new 
Result:result dbi_query(sqlquery)
    if (
result <= RESULT_FAILED) {
        new 
error[256]
        
dbi_error(sqlerror255)
        
log_amx("Error while quering SQL server for %s, can't check registration: %s"authiderror)
        
dbi_close(sql)
        return 
false
    
}
    else if (
result == RESULT_NONE || !dbi_nextrow(result)) {
        
dbi_close(sql)
        return 
false
    
}
    
    
gate_matchID get_cvar_pointer "matchID" )
    
format(queryLONGER"UPDATE players SET `in`='1' WHERE `matchID`='%d' AND `steamid`=^"%s^""get_pcvar_num(gate_matchID), authid)
    
dbi_query(sqlquery)
    
dbi_close(sql)
    
    return 
true
}

// here goes the database connection
bool:connect(&Sql:sql) {
    const 
LEN 128
    
new host[LEN], user[LEN], pass[LEN], db[LEN], error_msg[LEN]
    
    
get_cvar_string(CVAR_CHHOSThostLEN 2)
    
get_cvar_string(CVAR_CHUSERuserLEN 2)
    
get_cvar_string(CVAR_CHPASSpassLEN 2)
    
get_cvar_string(CVAR_CHDBdbLEN 2)
    
    
sql dbi_connect(hostuserpassdberror_msgLEN 2)
    
    if (!
sql) {
        
log_amx("ERROR - Can't connect to SQL db: %s"error_msg)
        return 
false
    
}
    
    return 
true
}

public 
plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
    
register_cvar(CVAR_CHHOST"ip")
    
register_cvar(CVAR_CHUSER"user")
    
register_cvar(CVAR_CHPASS"pw")
    
register_cvar(CVAR_CHDB"db")
    
register_cvar("matchID""1")
    
    new 
Sql:sql
    
if (!connect(sql)) {
        
log_amx("Couldn't connect to SQL database at plugin_init! Pausing plugin.")
        
pause("a")
        return
    }
    
    else
        
server_print("[%s] Connected successfully to SQL database."PLUGIN)
    
dbi_close(sql)
    
    


And offcurse i know SQLx is better but i'm without time to change the script to SQLx. And this is my first script in AMXX :)
And the variable warmup is part of a project I'm developing and this script make part.

spiider 03-15-2010 12:00

Re: Change Name (with SQL)
 
the querys are working without problem but i'm go change.

Exolent[jNr] 03-15-2010 22:40

Re: Change Name (with SQL)
 
Quote:

Originally Posted by xPaw (Post 1118134)
`steamid` = ^"%s^"
should be
`steamid` = '%s'

It's fine the way it is. :P

puttsmobiles 03-17-2010 13:41

Re: Change Name (with SQL)
 
Would you mind if I tested this?

spiider 03-18-2010 11:48

Re: Change Name (with SQL)
 
no problem you can test, is working in my server without problem, and i fix the connection problem with server.

If have some one interrest in this plugin i can make a better version and post plugin for be accepted.

puttsmobiles 03-18-2010 16:51

Re: Change Name (with SQL)
 
I tried it and it wont force the name change.

can you post a test SQL file so i can try it?

spiider 03-19-2010 10:59

Re: Change Name (with SQL)
 
Code:

-- ----------------------------
-- Table structure for `users`
-- ----------------------------
DROP TABLE IF EXISTS `users`;
CREATE TABLE `users` (
  `steamid` varchar(32) default 'STEAM_0:0:0000',
  `name` varchar(32) default NULL,
  PRIMARY KEY  (`steamid`),
  UNIQUE KEY `unique` (`name`)
) ENGINE=MyISAM AUTO_INCREMENT=328 DEFAULT CHARSET=latin1;

The script change name automatic, but your previous name ingame will be the same in console only. Only in the server will be the db name. Later i post some screen.


All times are GMT -4. The time now is 10:17.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.