[Release] Ban/UnBan(in SQL) + SQL Script

Joined
Jan 8, 2006
Messages
19
Reaction score
0
Code released by me! :)

Info:
!ban <Character name> ; Get's the UserID and then set banned to 1.
!unban <Character name> ; Get's the UserID and then set banned to 0.
!sql <SQL Query script> ; If you don't have acces to db, ingame feature becomes handy also! :)

Theres a confusion about !sql
This is how to use,
PHP:
!sql update users set GM='1' where username='benjooo'
For example.

What to do;

In MySQLM.h add
PHP:
static void Ban(int UserName);//Ban
static void unBan(int UserName);//UnBan
static void SQL(char* query);//SQL Query Execution
static int getID(char* username);//GetID

In MySQLM.cpp add
PHP:
void MySQL::Ban(int UserID){//code by benjooo
	char query[255];
	sprintf_s(query, 255, "update users set banned='1' where ID=%d",UserID);
	mysql_query(&maple_db,query);
	printf("UserID %d Banned!\n",UserID);
}

void MySQL::unBan(int UserID){//code by benjooo
	char query[255];
	sprintf_s(query, 255, "update users set banned='0' where ID=%d",UserID);
	mysql_query(&maple_db,query);
	printf("UserID %d Banned!\n",UserID);
}

void MySQL::SQL(char query[255]){//code by benjooo
		sprintf_s(query, 255, "%s", query);
		mysql_real_query(&maple_db, query, strlen(query));
}

int MySQL::getID(char *username){
	MYSQL_RES *mres;
	MYSQL_ROW mrow;
	char query[255]; 
	int ret = 0;
	sprintf_s(query, 255, "select userid from characters where name='%s';",username);
	mysql_real_query(&maple_db, query, strlen(query));
	mres = mysql_store_result(&maple_db);
	if (mres == 0 ){
		printf_s("\n\rError in getUserID SQL returned no rows (Mysql_error: %s)",mysql_error(&maple_db)); 
		printf_s("SQL Query is : %s",query);
	}
	else {
		if(mysql_num_rows(mres) > 0){
			mrow = mysql_fetch_row(mres);
			string mr = string((char*)mrow[0]);
			istringstream buffer(mr);
			buffer >> ret;
		}
	}
	mysql_free_result(mres);
	return ret;
}

In players.cpp add
PHP:
		else if(strcmp(command, "ban") ==0){//Ban
			char* user = next_token;
			printf("Selected %s\n", user);
			MySQL::Ban(MySQL::getID(user));
			printf("Banned %s\n", user); 
		}

		else if(strcmp(command, "unban") ==0){//Unban
			char* user = next_token;
			printf("Selected %s\n", user);
			MySQL::unBan(MySQL::getID(user));
			printf("Unbanned %s\n", user);
		}

		else if(strcmp(command, "sql") ==0){//Query Execution
			char* query = next_token;
			printf ("'%s' has been executed!", query);
			MySQL::SQL(query);
		}

Add this in players.CPP
PHP:
#include "MySQLM.h"
#include "mysql.h"

Sorry made an mistake this should be correct.

If you don't know where to place this code, then ur nothing but a plonker :P
I might've forgot something to include. My apologies for that.

Also i don't advice you to add !sql if you don't trust your GM's.

I hope i gave some support to MS-Source.

Gr.
 
Last edited:
Re: [Release] !Ban/UnBan(in SQL) + SQL Script

Well, I guess your C&Per's are spoon-fed once again, Nice release though i made this about 2 weeks ago

But, yeah this should work depending on the Login-ban-check
 
Re: [Release] !Ban/UnBan(in SQL) + SQL Script

Well, I guess your C&Per's are spoon-fed once again, Nice release though i made this about 2 weeks ago

But, yeah this should work depending on the Login-ban-check

I'm guessing you're one of those idiots who didnt read the Anti-Leech INFO sticky right? pfft.

ONTOPIC: Good release, MUCH more mandetory.
 
Re: [Release] !Ban/UnBan(in SQL) + SQL Script

hey, i got all these errors talking about winsock2, and does
static void Ban(int UserName);//Ban
static void unBan(int UserName);//UnBan
static void SQL(char* query);//SQL Query Execution
static int getID(char* username);//GetID
go in private or public in the MySQLm.h
 
Back