Go Back   EQEmulator Home > EQEmulator Forums > Development > Development::Server Code Submissions

Reply
 
Thread Tools Display Modes
  #1  
Old 01-28-2010, 06:27 PM
cybernine186
Sarnak
 
Join Date: Feb 2008
Posts: 87
Default COMMITTED: #timeban [name][days]

#timeban [name][days]

Allows you to ban a characters account for a specified number of days. The characters account will be banned for the number of days right down to the minute of when he/she was banned. Also this will return a -1 which tells the world server that the account is suspended and not banned.

I'v not tested this patch but it does compile just fine.


I am the Lead GM of the Vallon / Tallon Zek server and this was a much needed command and I thought I would share it with the EQ community.

SQL Code
Code:
ALTER TABLE `account` ADD `timebanned` DATETIME NOT NULL
Patch for latest version of PEQ
Code:
Index: common/database.cpp
===================================================================
--- common/database.cpp	(revision 1187)
+++ common/database.cpp	(working copy)
@@ -307,12 +307,19 @@
     MYSQL_RES *result;
     MYSQL_ROW row;
 
-	if (RunQuery(query, MakeAnyLenString(&query, "SELECT status FROM account WHERE id='%i'", account_id), errbuf, &result)) {
+	if (RunQuery(query, MakeAnyLenString(&query, "SELECT `status`, UNIX_TIMESTAMP(`timebanned`) as `timebanned`, UNIX_TIMESTAMP() as `current` FROM `account` WHERE `id` = %i", account_id), errbuf, &result)) {
 		safe_delete_array(query);
 		if (mysql_num_rows(result) == 1)
 		{
 			row = mysql_fetch_row(result);
 			sint16 status = atoi(row[0]);
+			sint32 timebanned = atoi(row[1]);
+			sint32 current = atoi(row[2]);
+			
+			// Check Time Banned
+			if(timebanned > current) {
+				return -1;
+			}
 
 			mysql_free_result(result);
 			return status;
Index: zone/command.cpp
===================================================================
--- zone/command.cpp	(revision 1187)
+++ zone/command.cpp	(working copy)
@@ -384,6 +384,7 @@
 		command_add("nologs","[status|normal|error|debug|quest|all] - Unsubscribe to a log type",250,command_nologs) ||
 		command_add("datarate","[rate] - Query/set datarate",100,command_datarate) ||
 		command_add("ban","[name] - Ban by character name",150,command_ban) ||
+		command_add("timeban","[name][days] - Ban by character name and for specificed number of days",150,command_timeban) ||
 		command_add("ipban","[IP address] - Ban IP by character name",200,command_ipban) ||
 		command_add("oocmute","[1/0] - Mutes OOC chat",200,command_oocmute) ||
 		command_add("revoke","[charname] [1/0] - Makes charname unable to talk on OOC",200,command_revoke) ||
@@ -6287,6 +6288,55 @@
 	}
 }
 
+void command_timeban(Client *c, const Seperator *sep)
+{
+	char errbuf[MYSQL_ERRMSG_SIZE];
+	char *query = 0;
+	MYSQL_RES *result;
+	MYSQL_ROW row;
+
+	if(sep->arg[1][0] == 0) {
+		c->Message(0, "Usage:  #ban [charname][days]");
+	} else {
+		database.RunQuery(query, MakeAnyLenString(&query, "SELECT `account_id` FROM `character_` WHERE `name` = '%s'", sep->arg[1]), errbuf, &result);
+		if(query) {
+			safe_delete_array(query);
+		}
+		if(mysql_num_rows(result)) {
+			row = mysql_fetch_row(result);
+			database.RunQuery(query, MakeAnyLenString(&query, "UPDATE `account` SET `timebanned` = DATE_ADD(NOW(), INTERVAL %i DAY) WHERE `id` = %i", sep->arg[1], atoi(row[0])), errbuf, 0);
+			c->Message(13,"Account number %i with the character %s has been temporary banned for %i days.", atoi(row[0]), sep->arg[1], sep->arg[2]);
+
+			ServerPacket* pack = new ServerPacket(ServerOP_FlagUpdate, 6);
+			*((int32*) pack->pBuffer) = atoi(row[0]);
+			*((sint16*) &pack->pBuffer[4]) = -2;
+			worldserver.SendPacket(pack);
+			safe_delete(pack);
+
+			Client *client = NULL;
+			client = entity_list.GetClientByName(sep->arg[1]);
+			if(client) {
+				client->Kick();
+			} else {
+				ServerPacket* pack = new ServerPacket(ServerOP_KickPlayer, sizeof(ServerKickPlayer_Struct));
+				ServerKickPlayer_Struct* skp = (ServerKickPlayer_Struct*) pack->pBuffer;
+				strcpy(skp->adminname, c->GetName());
+				strcpy(skp->name, sep->arg[1]);
+				skp->adminrank = c->Admin();
+				worldserver.SendPacket(pack);
+				safe_delete(pack);
+			}
+
+			mysql_free_result(result);
+		} else {
+			c->Message(13,"Character does not exist.");
+		}
+		if(query) {
+			safe_delete_array(query);
+		}
+	}
+}
+
 void command_ipban(Client *c, const Seperator *sep)
 {
 	if(sep->arg[1] == 0)
Index: zone/command.h
===================================================================
--- zone/command.h	(revision 1187)
+++ zone/command.h	(working copy)
@@ -245,6 +245,7 @@
 void command_setaapts(Client *c, const Seperator *sep);
 void command_stun(Client *c, const Seperator *sep);
 void command_ban(Client *c, const Seperator *sep);
+void command_timeban(Client *c, const Seperator *sep);
 void command_ipban(Client *c, const Seperator *sep);
 void command_oocmute(Client *c, const Seperator *sep);
 void command_revoke(Client *c, const Seperator *sep);
__________________
Lead GM Voidd of the Vallon / Tallon Zek Server
Reply With Quote
  #2  
Old 01-28-2010, 07:09 PM
trevius's Avatar
trevius
Developer
 
Join Date: Aug 2006
Location: USA
Posts: 5,946
Default

That looks really nice! I really like how it should allow you to keep the actual account status set to whatever it was previously set at, so when the timeban is over, they return to their previous account status.
__________________
Trevazar/Trevius Owner of: Storm Haven
Everquest Emulator FAQ (Frequently Asked Questions) - Read It!
Reply With Quote
  #3  
Old 01-28-2010, 07:38 PM
KLS
Administrator
 
Join Date: Sep 2006
Posts: 1,348
Default

Suspend would probably be a better name than timeban for this operation; you return -1 without freeing the result also.

I had thought we needed such a thing though so cheers.
Reply With Quote
  #4  
Old 01-28-2010, 10:37 PM
cybernine186
Sarnak
 
Join Date: Feb 2008
Posts: 87
Default

ugh...yea forgot about where I done the return without freeing the result.

in the database.cpp move

mysql_free_result(result);

above the

// Check Time Banned
if(timebanned > current) {
return -1;
}

and that will fix that small memory leak.
__________________
Lead GM Voidd of the Vallon / Tallon Zek Server
Reply With Quote
  #5  
Old 01-29-2010, 12:38 AM
cybernine186
Sarnak
 
Join Date: Feb 2008
Posts: 87
Default

Please use this patch instead....I never got a chance to test the prior patch as I did it in 5 minutes.

Here is a working patch and tested.
Code:
Index: common/database.cpp
===================================================================
--- common/database.cpp	(revision 1192)
+++ common/database.cpp	(working copy)
@@ -307,14 +307,21 @@
     MYSQL_RES *result;
     MYSQL_ROW row;
 
-	if (RunQuery(query, MakeAnyLenString(&query, "SELECT status FROM account WHERE id='%i'", account_id), errbuf, &result)) {
+	if (RunQuery(query, MakeAnyLenString(&query, "SELECT `status`, UNIX_TIMESTAMP(`timebanned`) as `timebanned`, UNIX_TIMESTAMP() as `current` FROM `account` WHERE `id` = %i", account_id), errbuf, &result)) {
 		safe_delete_array(query);
 		if (mysql_num_rows(result) == 1)
 		{
 			row = mysql_fetch_row(result);
 			sint16 status = atoi(row[0]);
-
+			sint32 timebanned = atoi(row[1]);
+			sint32 current = atoi(row[2]);
 			mysql_free_result(result);
+			
+			// Check Time Banned
+			if(timebanned > current) {
+				return -1;
+			}
+			
 			return status;
 		}
 		else
Index: zone/command.cpp
===================================================================
--- zone/command.cpp	(revision 1192)
+++ zone/command.cpp	(working copy)
@@ -384,6 +384,7 @@
 		command_add("nologs","[status|normal|error|debug|quest|all] - Unsubscribe to a log type",250,command_nologs) ||
 		command_add("datarate","[rate] - Query/set datarate",100,command_datarate) ||
 		command_add("ban","[name] - Ban by character name",150,command_ban) ||
+		command_add("timeban","[name][days] - Ban by character name and for specificed number of days",150,command_timeban) ||
 		command_add("ipban","[IP address] - Ban IP by character name",200,command_ipban) ||
 		command_add("oocmute","[1/0] - Mutes OOC chat",200,command_oocmute) ||
 		command_add("revoke","[charname] [1/0] - Makes charname unable to talk on OOC",200,command_revoke) ||
@@ -6287,6 +6288,55 @@
 	}
 }
 
+void command_timeban(Client *c, const Seperator *sep)
+{
+	char errbuf[MYSQL_ERRMSG_SIZE];
+	char *query = 0;
+	MYSQL_RES *result;
+	MYSQL_ROW row;
+
+	if(sep->arg[1][0] == 0) {
+		c->Message(0, "Usage:  #ban [charname][days]");
+	} else {
+		database.RunQuery(query, MakeAnyLenString(&query, "SELECT `account_id` FROM `character_` WHERE `name` = '%s'", sep->arg[1]), errbuf, &result);
+		if(query) {
+			safe_delete_array(query);
+		}
+		if(mysql_num_rows(result)) {
+			row = mysql_fetch_row(result);
+			database.RunQuery(query, MakeAnyLenString(&query, "UPDATE `account` SET `timebanned` = DATE_ADD(NOW(), INTERVAL %i DAY) WHERE `id` = %i", atoi(sep->arg[2]), atoi(row[0])), errbuf, 0);
+			c->Message(13,"Account number %i with the character %s has been temporary banned for %i days.", atoi(row[0]), sep->arg[1], sep->arg[2]);
+
+			ServerPacket* pack = new ServerPacket(ServerOP_FlagUpdate, 6);
+			*((int32*) pack->pBuffer) = atoi(row[0]);
+			*((sint16*) &pack->pBuffer[4]) = -2;
+			worldserver.SendPacket(pack);
+			safe_delete(pack);
+
+			Client *client = NULL;
+			client = entity_list.GetClientByName(sep->arg[1]);
+			if(client) {
+				client->Kick();
+			} else {
+				ServerPacket* pack = new ServerPacket(ServerOP_KickPlayer, sizeof(ServerKickPlayer_Struct));
+				ServerKickPlayer_Struct* skp = (ServerKickPlayer_Struct*) pack->pBuffer;
+				strcpy(skp->adminname, c->GetName());
+				strcpy(skp->name, sep->arg[1]);
+				skp->adminrank = c->Admin();
+				worldserver.SendPacket(pack);
+				safe_delete(pack);
+			}
+
+			mysql_free_result(result);
+		} else {
+			c->Message(13,"Character does not exist.");
+		}
+		if(query) {
+			safe_delete_array(query);
+		}
+	}
+}
+
 void command_ipban(Client *c, const Seperator *sep)
 {
 	if(sep->arg[1] == 0)
Index: zone/command.h
===================================================================
--- zone/command.h	(revision 1192)
+++ zone/command.h	(working copy)
@@ -245,6 +245,7 @@
 void command_setaapts(Client *c, const Seperator *sep);
 void command_stun(Client *c, const Seperator *sep);
 void command_ban(Client *c, const Seperator *sep);
+void command_timeban(Client *c, const Seperator *sep);
 void command_ipban(Client *c, const Seperator *sep);
 void command_oocmute(Client *c, const Seperator *sep);
 void command_revoke(Client *c, const Seperator *sep);
__________________
Lead GM Voidd of the Vallon / Tallon Zek Server

Last edited by Derision; 01-29-2010 at 01:18 PM.. Reason: Pinned for submission
Reply With Quote
  #6  
Old 01-29-2010, 03:51 PM
Derision
Developer
 
Join Date: Feb 2004
Location: UK
Posts: 1,540
Default

I've just been testing this, and it works

Is there any reason for sending the ServerOP_FlagUpdate, since we are kicking the character anyway ? I commented that bit out and it seems to work just the same.
Reply With Quote
  #7  
Old 01-29-2010, 05:34 PM
cybernine186
Sarnak
 
Join Date: Feb 2008
Posts: 87
Default

Most likely not but I basically used the same code as #ban so I didn't even bother looking at the rest of the code.

I know this code will help the GM over the problem childs on the servers who cause drama. I know that the VZTZ server is the only PVP server and this feature will help free up time for my GM's.
__________________
Lead GM Voidd of the Vallon / Tallon Zek Server
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

   

All times are GMT -4. The time now is 03:02 PM.


 

Everquest is a registered trademark of Daybreak Game Company LLC.
EQEmulator is not associated or affiliated in any way with Daybreak Game Company LLC.
Except where otherwise noted, this site is licensed under a Creative Commons License.
       
Powered by vBulletin®, Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Template by Bluepearl Design and vBulletin Templates - Ver3.3