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

Reply
 
Thread Tools Display Modes
  #1  
Old 10-02-2009, 04:00 AM
Shin Noir's Avatar
Shin Noir
Legendary Member
 
Join Date: Apr 2002
Location: Seattle, WA
Posts: 502
Default #transferchar [charname] [acctid]

Saw Rogean post this, took a couple minutes to try to write it. I did not test this at all, which I should, but I'm not at home busy on a laptop.. Let me know if anything is wrong (atoi function i am not familiar with).
Code:
Index: common/database.cpp
===================================================================
--- common/database.cpp	(revision 1004)
+++ common/database.cpp	(working copy)
@@ -1613,6 +1613,24 @@
 	return true;
 }
 
+
+bool Database::TransferCharacterToAccount(int32 charid, int32 acctid) {
+	char errbuf[MYSQL_ERRMSG_SIZE];
+	char *query = 0;
+	int32	affected_rows = 0;
+
+	if (!RunQuery(query, MakeAnyLenString(&query, "UPDATE `character_` SET `account_id` = '%i' WHERE `id` = '%i';", acctid,charid), errbuf, 0,&affected_rows)) {
+		cerr << "Error in TransferCharacterToACcount(charid, acctid) query '" << query << "' " << errbuf << endl;
+		return false;
+	}
+	safe_delete_array(query);
+
+	if (affected_rows == 0)
+		return false;
+
+	return true;
+}
+
 int8 Database::CopyCharacter(const char* oldname, const char* newname, int32 acctid) {
 	char errbuf[MYSQL_ERRMSG_SIZE];
 	char *query = 0;
Index: common/database.h
===================================================================
--- common/database.h	(revision 1004)
+++ common/database.h	(working copy)
@@ -116,6 +116,7 @@
 	bool	MoveCharacterToZone(const char* charname, const char* zonename);
 	bool	MoveCharacterToZone(const char* charname, const char* zonename,int32 zoneid);
 	bool	MoveCharacterToZone(int32 iCharID, const char* iZonename);
+	bool	TransferCharacterToAccount(int32 charid, int32 acctid);
 	bool	UpdateName(const char* oldname, const char* newname);
 	bool	SetHackerFlag(const char* accountname, const char* charactername, const char* hacked);
 	bool	SetMQDetectionFlag(const char* accountname, const char* charactername, const char* hacked, const char* zone);
Index: zone/command.cpp
===================================================================
--- zone/command.cpp	(revision 1004)
+++ zone/command.cpp	(working copy)
@@ -189,6 +189,7 @@
 		command_add("tgczone",NULL,0,command_peqzone) ||
 		command_add("showbuffs","- List buffs active on your target or you if no target",50,command_showbuffs) ||
 		command_add("movechar","[charname] [zonename] - Move charname to zonename",50,command_movechar) ||
+		command_add("transferchar","[charname] [accountid] - Move charname to accountid",200,command_transferchar) ||
 		command_add("viewpetition","[petition number] - View a petition",20,command_viewpetition) ||
 		command_add("petitioninfo","[petition number] - Get info about a petition",20,command_petitioninfo) ||
 		command_add("delpetition","[petition number] - Delete a petition",20,command_delpetition) ||
@@ -1602,6 +1603,25 @@
 	}
 }
 
+void command_transferchar(Client *c, const Seperator *sep)
+{ //Shin: Transfer a character from one login to another.
+	if(sep->arg[1][0] == 0 || sep->arg[2][0] == 0)
+		c->Message(0, "Usage: #transferchar [charactername] [accountid] ");
+	else
+	{
+		int32 charid = database.GetCharacterID(sep->arg[2]);
+		if (charid)
+		{
+			if (!database.TransferCharacterToAccount(charid, atoi(sep->arg[1])))
+				c->Message(0, "Character failed to move!");
+			else
+				c->Message(0, "Character has been moved.");
+		}
+		else
+			c->Message(0, "Character name not found.");
+	}
+}
+
 void command_viewpetition(Client *c, const Seperator *sep)
 {
 	if (sep->arg[1][0] == 0)
Index: zone/command.h
===================================================================
--- zone/command.h	(revision 1004)
+++ zone/command.h	(working copy)
@@ -96,6 +96,7 @@
 void command_peqzone(Client *c, const Seperator *sep);
 void command_showbuffs(Client *c, const Seperator *sep);
 void command_movechar(Client *c, const Seperator *sep);
+void command_transferchar(Client *c, const Seperator *sep);
 void command_viewpetition(Client *c, const Seperator *sep);
 void command_petitioninfo(Client *c, const Seperator *sep);
 void command_delpetition(Client *c, const Seperator *sep);
__________________

~Shin Noir
DungeonEQ.com
Reply With Quote
  #2  
Old 10-02-2009, 10:49 AM
Secrets's Avatar
Secrets
Demi-God
 
Join Date: May 2007
Location: b
Posts: 1,450
Default

Shin,

I love you.

Probably one of the more useful things you have written!
Reply With Quote
  #3  
Old 10-02-2009, 11:37 AM
Shin Noir's Avatar
Shin Noir
Legendary Member
 
Join Date: Apr 2002
Location: Seattle, WA
Posts: 502
Default

Quote:
Originally Posted by Secrets View Post
Shin,

I love you.

Probably one of the more useful things you have written!
Meh. Teleport Bind is insanely useful, slacker.
This is a lazy man's tool. Rogean showed how easy this is to do. I just turned it into a command cuz he said he was thinking about doing it. :P
__________________

~Shin Noir
DungeonEQ.com
Reply With Quote
  #4  
Old 10-02-2009, 12:30 PM
Pend
Fire Beetle
 
Join Date: Sep 2009
Posts: 16
Default

Shin, you may want to think about how to handle if the character being transferred is in use. Maybe a forced disconnect?
Reply With Quote
  #5  
Old 10-02-2009, 12:41 PM
Shin Noir's Avatar
Shin Noir
Legendary Member
 
Join Date: Apr 2002
Location: Seattle, WA
Posts: 502
Default

Also verifying the account ID exists would be nice. I probably should do that, but.. Meh. I don't even know if this code works still. Need to sit down and test it, then i'll go through and optimize with stupid-proofing it. I could also probably write a switch conversion so it will accept account login names or account id's, since with that info doing a character transfer can be very easy.

But then again Pend, if a character is moved to another account, what does that do in potential bugs? It isn't like there is much for ties between characters and accounts, if the character is logged in and the account that owns it is swapped, the only time account will be fetched again is when the character logs off or does a save etc and when it does it'll just save to the new account name... I should test that, log out and see what characters come up if I transfer a char between accounts. XD
__________________

~Shin Noir
DungeonEQ.com
Reply With Quote
  #6  
Old 10-02-2009, 03:29 PM
pfyon's Avatar
pfyon
Discordant
 
Join Date: Mar 2009
Location: Ottawa
Posts: 495
Default

What happens in the following situation?

1) Player uses #transferchar to transfer Char A from Account A to Account B
2) Player logs in Char A from Account B while the original char is still in game
Reply With Quote
  #7  
Old 10-02-2009, 04:15 PM
Rogean's Avatar
Rogean
Administrator
 
Join Date: Jul 2003
Location: Massachusetts
Posts: 708
Default

Would kick them off.. the same thing that happens when you log into your own account twice.
__________________
EQEmulator Developer / Administrator
Reply With Quote
  #8  
Old 11-22-2009, 08:01 PM
Sodapop12
Fire Beetle
 
Join Date: Jun 2008
Location: California
Posts: 1
Default

i dont get how to do this
Reply With Quote
  #9  
Old 01-24-2010, 08:13 PM
tricyclethief2
Fire Beetle
 
Join Date: Nov 2008
Location: .
Posts: 21
Default

I know this thread is little old but just wondering if this is the easiest way to xfer toons to new accounts. also does this move gear/factions/flags etc or any ideas on a easy way to do this?
Reply With Quote
  #10  
Old 01-24-2010, 09:10 PM
cavedude's Avatar
cavedude
The PEQ Dude
 
Join Date: Apr 2003
Location: -
Posts: 1,988
Default

Quote:
Originally Posted by tricyclethief2 View Post
I know this thread is little old but just wondering if this is the easiest way to xfer toons to new accounts. also does this move gear/factions/flags etc or any ideas on a easy way to do this?
I just use a PHP script, but the code above would be good for those who are in-game more. Everything gets transferred over since you are only changing the account id, nothing else.
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 04:54 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