Shin Noir
10-02-2009, 04:00 AM
Saw Rogean post this (http://www.eqemulator.net/forums/showpost.php?p=179525&postcount=2), 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).
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);
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);