mirror of
https://github.com/EQEmu/Server.git
synced 2026-09-05 11:26:35 +00:00
svn -> git Migration
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
|
||||
#Mysql flags, for linuxthreads
|
||||
#MYSQL_FLAGS=`mysql_config --cflags`
|
||||
#MYSQL_LIB=`mysql_config --libs`
|
||||
MYSQL_FLAGS=-I'/usr/local/include/mysql'
|
||||
MYSQL_LIBS=-L'/usr/local/lib/mysql' -llmysqlclient -lz -lcrypt -lm
|
||||
|
||||
#linux threads flags:
|
||||
LTFLAGS=-I/usr/local/include/pthread/linuxthreads -D_GNU_SOURCE -D__USE_UNIX98 -D_REENTRANT -D_THREAD_SAFE
|
||||
LTLDFLAGS=-llthread -llstdc++ -llsupc++ -llgcc_r -L/usr/local/lib
|
||||
|
||||
CXXFLAGS=-ggdb -O -pipe -Wall -I. -I../common -fno-inline -DFREEBSD $(LTFLAGS) $(MYSQL_FLAGS)
|
||||
LDFLAGS=-lpcap -lz -rdynamic -O2 -ggdb -pipe -L/usr/local/lib $(LTLDFLAGS)
|
||||
|
||||
|
||||
include Makefile.common
|
||||
@@ -0,0 +1,24 @@
|
||||
|
||||
GOBJS=.obj/Mutex.o .obj/unix.o \
|
||||
.obj/dbcore.o
|
||||
|
||||
all: export_char import_char
|
||||
|
||||
export_char: $(GOBJS) export_char.o
|
||||
g++ -I.. $^ $(LDFLAGS) $(MYSQL_LIBS) -o $@
|
||||
|
||||
import_char: $(GOBJS) import_char.o
|
||||
g++ -I.. $^ $(LDFLAGS) $(MYSQL_LIBS) -o $@
|
||||
|
||||
clean:
|
||||
rm -f import_char export_char *.o
|
||||
|
||||
.obj/%.o: ../../common/%.cpp ../../common/%.h
|
||||
mkdir -p .obj
|
||||
g++ -I.. $(CXXFLAGS) -c $< -o $@
|
||||
|
||||
%.o: %.cpp %.h
|
||||
mkdir -p .obj
|
||||
g++ -I.. $(CXXFLAGS) -c $< -o $@
|
||||
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
#ifndef CHAR_FORMAT_H
|
||||
#define CHAR_FORMAT_H
|
||||
|
||||
#include "../common/types.h"
|
||||
|
||||
#define CHAR_MAGIC 0xaa77e598
|
||||
|
||||
#pragma pack(1)
|
||||
struct CharHeader {
|
||||
uint32 char_magic;
|
||||
|
||||
//character_ data
|
||||
char name[64];
|
||||
float x;
|
||||
float y;
|
||||
float z;
|
||||
char zone_name[32];
|
||||
uint16 zone_id;
|
||||
uint32 profile_length;
|
||||
uint32 extprofile_length;
|
||||
|
||||
//faction_values
|
||||
uint32 faction_value_count;
|
||||
|
||||
//inventory
|
||||
uint32 inventory_count;
|
||||
|
||||
//sharedbank
|
||||
uint32 sharedbank_count;
|
||||
|
||||
//quest_globals
|
||||
uint32 quest_globals_count;
|
||||
|
||||
/*
|
||||
Variable length fields:
|
||||
byte PlayerProfile[profile_length];
|
||||
byte ExtendedProfile[extprofile_length];
|
||||
FactionValueRecord faction_values[faction_value_count];
|
||||
InventoryEntry inventory[inventory_count];
|
||||
InventoryEntry sharedbank[sharedbank_count];
|
||||
QuestGlobalEntry quest_globals[quest_globals_count];
|
||||
|
||||
*/
|
||||
};
|
||||
|
||||
|
||||
struct FactionValueRecord {
|
||||
sint32 faction_id;
|
||||
sint32 current_value;
|
||||
};
|
||||
|
||||
struct InventoryEntry {
|
||||
uint16 slotid;
|
||||
uint32 itemid;
|
||||
sint16 charges;
|
||||
uint32 colors;
|
||||
uint32 augs[5];
|
||||
uint8 instnodrop;
|
||||
};
|
||||
|
||||
struct QuestGlobalEntry {
|
||||
sint32 npcid;
|
||||
sint32 zoneid;
|
||||
char name[66];
|
||||
char value[66];
|
||||
sint32 expdate;
|
||||
};
|
||||
|
||||
|
||||
#pragma pack()
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,110 @@
|
||||
# Microsoft Developer Studio Project File - Name="charmove" - Package Owner=<4>
|
||||
# Microsoft Developer Studio Generated Build File, Format Version 6.00
|
||||
# ** DO NOT EDIT **
|
||||
|
||||
# TARGTYPE "Win32 (x86) Console Application" 0x0103
|
||||
|
||||
CFG=charmove - Win32 Debug
|
||||
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
|
||||
!MESSAGE use the Export Makefile command and run
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "charmove.mak".
|
||||
!MESSAGE
|
||||
!MESSAGE You can specify a configuration when running NMAKE
|
||||
!MESSAGE by defining the macro CFG on the command line. For example:
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "charmove.mak" CFG="charmove - Win32 Debug"
|
||||
!MESSAGE
|
||||
!MESSAGE Possible choices for configuration are:
|
||||
!MESSAGE
|
||||
!MESSAGE "charmove - Win32 Release" (based on "Win32 (x86) Console Application")
|
||||
!MESSAGE "charmove - Win32 Debug" (based on "Win32 (x86) Console Application")
|
||||
!MESSAGE
|
||||
|
||||
# Begin Project
|
||||
# PROP AllowPerConfigDependencies 0
|
||||
# PROP Scc_ProjName ""
|
||||
# PROP Scc_LocalPath ""
|
||||
CPP=cl.exe
|
||||
RSC=rc.exe
|
||||
|
||||
!IF "$(CFG)" == "charmove - Win32 Release"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 0
|
||||
# PROP BASE Output_Dir "Release"
|
||||
# PROP BASE Intermediate_Dir "Release"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 0
|
||||
# PROP Output_Dir "Release"
|
||||
# PROP Intermediate_Dir "Release"
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
|
||||
# ADD CPP /nologo /W3 /GX /O2 /I "." /I ".." /I "../common" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /FD /c
|
||||
# SUBTRACT CPP /YX
|
||||
# ADD BASE RSC /l 0x409 /d "NDEBUG"
|
||||
# ADD RSC /l 0x409 /d "NDEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
|
||||
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib wsock32.lib zlib.lib mysqlclient.lib /nologo /subsystem:console /machine:I386 /libpath:"c:\mysql\lib\opt" /libpath:"c:\eqemu\lib"
|
||||
|
||||
!ELSEIF "$(CFG)" == "charmove - Win32 Debug"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 1
|
||||
# PROP BASE Output_Dir "Debug"
|
||||
# PROP BASE Intermediate_Dir "Debug"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 1
|
||||
# PROP Output_Dir "Debug"
|
||||
# PROP Intermediate_Dir "Debug"
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
|
||||
# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /FD /GZ /c
|
||||
# SUBTRACT CPP /YX
|
||||
# ADD BASE RSC /l 0x409 /d "_DEBUG"
|
||||
# ADD RSC /l 0x409 /d "_DEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
|
||||
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib wsock32.lib zlib.lib mysqlclient.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept /libpath:"c:\mysql\lib\opt" /libpath:"c:\eqemu\lib"
|
||||
|
||||
!ENDIF
|
||||
|
||||
# Begin Target
|
||||
|
||||
# Name "charmove - Win32 Release"
|
||||
# Name "charmove - Win32 Debug"
|
||||
# Begin Group "Source Files"
|
||||
|
||||
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\common\dbcore.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\export_char.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\common\Mutex.cpp
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "Header Files"
|
||||
|
||||
# PROP Default_Filter "h;hpp;hxx;hm;inl"
|
||||
# End Group
|
||||
# Begin Group "Resource Files"
|
||||
|
||||
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
|
||||
# End Group
|
||||
# End Target
|
||||
# End Project
|
||||
@@ -0,0 +1,263 @@
|
||||
#include "../common/types.h"
|
||||
//#include "../common/eq_packet_structs.h"
|
||||
#include <stdio.h>
|
||||
#include <mysql.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <vector>
|
||||
using namespace std;
|
||||
|
||||
#include "../common/dbcore.h"
|
||||
|
||||
#include "char_format.h"
|
||||
|
||||
void usage() {
|
||||
printf("Usage: export_char [list|charid] [outfile]\n");
|
||||
printf(" if charid is 'list' then all char IDs will be listed with names\n");
|
||||
printf(" note: this will not work on char ID 0\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
|
||||
const char *outfile;
|
||||
|
||||
if(argc != 3)
|
||||
usage();
|
||||
int charid = atoi(argv[1]);
|
||||
if(charid == 0)
|
||||
usage();
|
||||
outfile = argv[2];
|
||||
|
||||
char *query = new char[1024];
|
||||
char host[200], user[200], passwd[200], database[200];
|
||||
int32 port=0;
|
||||
bool compression = false;
|
||||
bool items[6] = {false, false, false, false, false, false};
|
||||
|
||||
if(!DBcore::ReadDBINI(host, user, passwd, database, port, compression, items)) {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (!items[0] || !items[1] || !items[2] || !items[3])
|
||||
{
|
||||
printf ("Incomplete DB.INI file.\n");
|
||||
exit (1);
|
||||
}
|
||||
|
||||
MYSQL m;
|
||||
|
||||
mysql_init(&m);
|
||||
|
||||
if(!mysql_real_connect(&m, host, user, passwd, database, 0, NULL, 0)) {
|
||||
printf("Unable to connect 1: %s.\n", mysql_error(&m));
|
||||
return(1);
|
||||
}
|
||||
|
||||
CharHeader header;
|
||||
char *ppbuffer;
|
||||
char *eppbuffer;
|
||||
/* FactionValueRecord *factions;
|
||||
InventoryEntry *inventory;
|
||||
InventoryEntry *sharedbank;
|
||||
QuestGlobalEntry *qglobals;*/
|
||||
|
||||
sprintf(query, "SELECT name,profile,extprofile,x,y,z,zonename,zoneid FROM character_ WHERE id=%d", charid);
|
||||
if(mysql_query(&m, query) != 0) {
|
||||
printf("Unable to query.\n");
|
||||
return(1);
|
||||
}
|
||||
|
||||
MYSQL_RES *res = mysql_use_result(&m);
|
||||
if(res == NULL) {
|
||||
printf("Unable to use character_ res.\n");
|
||||
return(1);
|
||||
}
|
||||
MYSQL_ROW row;
|
||||
row = mysql_fetch_row(res);
|
||||
if(row == NULL) {
|
||||
printf("Unable to find a char with id %d\n", charid);
|
||||
return(1);
|
||||
}
|
||||
unsigned long* lengths;
|
||||
lengths = mysql_fetch_lengths(res);
|
||||
|
||||
header.char_magic = CHAR_MAGIC;
|
||||
strcpy(header.name, row[0]);
|
||||
header.profile_length = lengths[1];
|
||||
header.extprofile_length = lengths[2];
|
||||
header.x = atof(row[3]);
|
||||
header.y = atof(row[4]);
|
||||
header.z = atof(row[5]);
|
||||
strcpy(header.zone_name, row[6]);
|
||||
header.zone_id = atoi(row[7]);
|
||||
//copy in blobs
|
||||
ppbuffer = new char[header.profile_length];
|
||||
eppbuffer = new char[header.extprofile_length];
|
||||
memcpy(ppbuffer, row[1], header.profile_length);
|
||||
memcpy(eppbuffer, row[2], header.extprofile_length);
|
||||
|
||||
mysql_free_result(res);
|
||||
|
||||
//query faction
|
||||
sprintf(query, "SELECT faction_id,current_value FROM faction_values WHERE char_id=%d", charid);
|
||||
if(mysql_query(&m, query) != 0) {
|
||||
printf("Unable to query faction: %s\n", mysql_error(&m));
|
||||
return(1);
|
||||
}
|
||||
res = mysql_use_result(&m);
|
||||
if(res == NULL) {
|
||||
printf("Unable to use faction res.\n");
|
||||
return(1);
|
||||
}
|
||||
vector<FactionValueRecord> fr;
|
||||
while((row = mysql_fetch_row(res))) {
|
||||
FactionValueRecord r;
|
||||
r.faction_id = atoi(row[0]);
|
||||
r.current_value = atoi(row[1]);
|
||||
fr.push_back(r);
|
||||
}
|
||||
mysql_free_result(res);
|
||||
|
||||
//query inventory
|
||||
sprintf(query, "SELECT slotid,itemid,charges,color,augslot1,augslot2,augslot3,augslot4,augslot5,instnodrop FROM inventory WHERE charid=%d", charid);
|
||||
if(mysql_query(&m, query) != 0) {
|
||||
printf("Unable to query inventory: %s\n", mysql_error(&m));
|
||||
return(1);
|
||||
}
|
||||
res = mysql_use_result(&m);
|
||||
if(res == NULL) {
|
||||
printf("Unable to use inventory res.\n");
|
||||
return(1);
|
||||
}
|
||||
vector<InventoryEntry> inv;
|
||||
while((row = mysql_fetch_row(res))) {
|
||||
InventoryEntry r;
|
||||
r.slotid = atoi(row[0]);
|
||||
r.itemid = atoi(row[1]);
|
||||
r.charges = atoi(row[2]);
|
||||
r.colors = atoi(row[3]);
|
||||
r.augs[0] = atoi(row[4]);
|
||||
r.augs[1] = atoi(row[5]);
|
||||
r.augs[2] = atoi(row[6]);
|
||||
r.augs[3] = atoi(row[7]);
|
||||
r.augs[4] = atoi(row[8]);
|
||||
inv.push_back(r);
|
||||
}
|
||||
mysql_free_result(res);
|
||||
|
||||
//query shared bank
|
||||
sprintf(query, "SELECT slotid,itemid,charges,augslot1,augslot2,augslot3,augslot4,augslot5 FROM sharedbank,character_ WHERE sharedbank.acctid = character_.account_id AND character_.id=%d", charid);
|
||||
if(mysql_query(&m, query) != 0) {
|
||||
printf("Unable to query shared bank: %s\n", mysql_error(&m));
|
||||
return(1);
|
||||
}
|
||||
res = mysql_use_result(&m);
|
||||
if(res == NULL) {
|
||||
printf("Unable to use shared bank res.\n");
|
||||
return(1);
|
||||
}
|
||||
vector<InventoryEntry> sb;
|
||||
while((row = mysql_fetch_row(res))) {
|
||||
InventoryEntry r;
|
||||
r.slotid = atoi(row[0]);
|
||||
r.itemid = atoi(row[1]);
|
||||
r.charges = atoi(row[2]);
|
||||
r.augs[0] = atoi(row[3]);
|
||||
r.augs[1] = atoi(row[4]);
|
||||
r.augs[2] = atoi(row[5]);
|
||||
r.augs[3] = atoi(row[6]);
|
||||
r.augs[4] = atoi(row[7]);
|
||||
sb.push_back(r);
|
||||
}
|
||||
mysql_free_result(res);
|
||||
|
||||
//query quest_globals
|
||||
sprintf(query, "SELECT npcid,zoneid,name,value,expdate FROM quest_globals WHERE charid=%d", charid);
|
||||
if(mysql_query(&m, query) != 0) {
|
||||
printf("Unable to query quest globals: %s\n", mysql_error(&m));
|
||||
return(1);
|
||||
}
|
||||
res = mysql_use_result(&m);
|
||||
if(res == NULL) {
|
||||
printf("Unable to use quest globals res.\n");
|
||||
return(1);
|
||||
}
|
||||
vector<QuestGlobalEntry> qg;
|
||||
while((row = mysql_fetch_row(res))) {
|
||||
QuestGlobalEntry r;
|
||||
r.npcid = atoi(row[0]);
|
||||
r.zoneid = atoi(row[1]);
|
||||
strcpy(r.name, row[2]);
|
||||
strcpy(r.value, row[3]);
|
||||
r.expdate = atoi(row[4]);
|
||||
qg.push_back(r);
|
||||
}
|
||||
mysql_free_result(res);
|
||||
|
||||
mysql_close(&m);
|
||||
|
||||
|
||||
FILE *outf = fopen(outfile, "wb");
|
||||
if(outf == NULL) {
|
||||
printf("Unable to open output file %s\n", outfile);
|
||||
return(1);
|
||||
}
|
||||
|
||||
//fill in our counters
|
||||
header.faction_value_count = fr.size();
|
||||
header.inventory_count = inv.size();
|
||||
header.sharedbank_count = sb.size();
|
||||
header.quest_globals_count = qg.size();
|
||||
|
||||
//write header
|
||||
fwrite(&header, 1, sizeof(header), outf);
|
||||
|
||||
//write out pp and epp
|
||||
fwrite(ppbuffer, 1, header.profile_length, outf);
|
||||
fwrite(eppbuffer, 1, header.extprofile_length, outf);
|
||||
|
||||
//write out our variable length segments
|
||||
vector<FactionValueRecord>::iterator curfr, endfr;
|
||||
curfr = fr.begin();
|
||||
endfr = fr.end();
|
||||
for(; curfr != endfr; curfr++) {
|
||||
FactionValueRecord &r = *curfr;
|
||||
fwrite(&r, 1, sizeof(FactionValueRecord), outf);
|
||||
}
|
||||
|
||||
vector<InventoryEntry>::iterator curi, endi;
|
||||
curi = inv.begin();
|
||||
endi = inv.end();
|
||||
for(; curi != endi; curi++) {
|
||||
InventoryEntry &i = *curi;
|
||||
fwrite(&i, 1, sizeof(InventoryEntry), outf);
|
||||
}
|
||||
|
||||
curi = sb.begin();
|
||||
endi = sb.end();
|
||||
for(; curi != endi; curi++) {
|
||||
InventoryEntry &i = *curi;
|
||||
fwrite(&i, 1, sizeof(InventoryEntry), outf);
|
||||
}
|
||||
|
||||
vector<QuestGlobalEntry>::iterator curqg, endqg;
|
||||
curqg = qg.begin();
|
||||
endqg = qg.end();
|
||||
for(; curqg != endqg; curqg++) {
|
||||
QuestGlobalEntry &r = *curqg;
|
||||
fwrite(&r, 1, sizeof(QuestGlobalEntry), outf);
|
||||
}
|
||||
|
||||
fclose(outf);
|
||||
|
||||
return(0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,190 @@
|
||||
#include "../common/types.h"
|
||||
//#include "../common/eq_packet_structs.h"
|
||||
#include <stdio.h>
|
||||
#include <mysql.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "../common/dbcore.h"
|
||||
|
||||
#include "char_format.h"
|
||||
|
||||
void usage() {
|
||||
printf("Usage: import_char [accountid] [infile]\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
|
||||
const char *infile;
|
||||
|
||||
if(argc != 3)
|
||||
usage();
|
||||
int accountid = atoi(argv[1]);
|
||||
if(accountid == 0)
|
||||
usage();
|
||||
infile = argv[2];
|
||||
|
||||
char *query = new char[1024000];
|
||||
char *cursor;
|
||||
char host[200], user[200], passwd[200], database[200];
|
||||
int32 port=0;
|
||||
bool compression = false;
|
||||
bool items[6] = {false, false, false, false, false, false};
|
||||
|
||||
if(!DBcore::ReadDBINI(host, user, passwd, database, port, compression, items)) {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (!items[0] || !items[1] || !items[2] || !items[3])
|
||||
{
|
||||
printf ("Incomplete DB.INI file.\n");
|
||||
exit (1);
|
||||
}
|
||||
|
||||
MYSQL m;
|
||||
|
||||
mysql_init(&m);
|
||||
|
||||
if(!mysql_real_connect(&m, host, user, passwd, database, 0, NULL, 0)) {
|
||||
printf("Unable to connect 1: %s.\n", mysql_error(&m));
|
||||
return(1);
|
||||
}
|
||||
|
||||
CharHeader header;
|
||||
char *ppbuffer;
|
||||
char *eppbuffer;
|
||||
FactionValueRecord *factions;
|
||||
InventoryEntry *inventory;
|
||||
InventoryEntry *sharedbank;
|
||||
QuestGlobalEntry *qglobals;
|
||||
|
||||
FILE *inf = fopen(infile, "rb");
|
||||
if(inf == NULL) {
|
||||
printf("Unable to open infile %s\n", infile);
|
||||
return(1);
|
||||
}
|
||||
|
||||
if(fread(&header, sizeof(header), 1, inf) != 1) {
|
||||
printf("Error reading header.\n");
|
||||
return(1);
|
||||
}
|
||||
|
||||
ppbuffer = new char[header.profile_length];
|
||||
eppbuffer = new char[header.extprofile_length];
|
||||
factions = new FactionValueRecord[header.faction_value_count];
|
||||
inventory = new InventoryEntry[header.inventory_count];
|
||||
sharedbank = new InventoryEntry[header.sharedbank_count];
|
||||
qglobals = new QuestGlobalEntry[header.quest_globals_count];
|
||||
|
||||
//read all the shit in
|
||||
if(fread(ppbuffer, header.profile_length, 1, inf) != 1) {
|
||||
printf("Error reading pp.\n");
|
||||
return(1);
|
||||
}
|
||||
if(fread(eppbuffer, header.extprofile_length, 1, inf) != 1) {
|
||||
printf("Error reading epp.\n");
|
||||
return(1);
|
||||
}
|
||||
if(fread(factions, sizeof(FactionValueRecord), header.faction_value_count, inf) != header.faction_value_count) {
|
||||
printf("Error reading factions.\n");
|
||||
return(1);
|
||||
}
|
||||
if(fread(inventory, sizeof(InventoryEntry), header.inventory_count, inf) != header.inventory_count) {
|
||||
printf("Error reading inventory.\n");
|
||||
return(1);
|
||||
}
|
||||
if(fread(sharedbank, sizeof(InventoryEntry), header.sharedbank_count, inf) != header.sharedbank_count) {
|
||||
printf("Error reading sharedbank.\n");
|
||||
return(1);
|
||||
}
|
||||
if(fread(qglobals, sizeof(QuestGlobalEntry), header.quest_globals_count, inf) != header.quest_globals_count) {
|
||||
printf("Error reading quest globals.\n");
|
||||
return(1);
|
||||
}
|
||||
|
||||
fclose(inf);
|
||||
|
||||
cursor = query;
|
||||
cursor += sprintf(cursor, "INSERT INTO character_ "
|
||||
"(account_id,name,profile,extprofile,x,y,z,zonename,zoneid)"
|
||||
"VALUES(%d,'%s','", accountid, header.name );
|
||||
cursor += mysql_real_escape_string(&m, cursor, (const char *) ppbuffer, header.profile_length);
|
||||
cursor += sprintf(cursor, "','");
|
||||
cursor += mysql_real_escape_string(&m, cursor, (const char *) eppbuffer, header.extprofile_length);
|
||||
sprintf(cursor, "',%f,%f,%f,'%s',%d)", header.x, header.y, header.z, header.zone_name, header.zone_id);
|
||||
if(mysql_query(&m, query) != 0) {
|
||||
printf("Unable to insert character: %s\n", mysql_error(&m));
|
||||
return(1);
|
||||
}
|
||||
int charid = mysql_insert_id(&m);
|
||||
uint32 r;
|
||||
|
||||
//faction
|
||||
for(r = 0; r < header.faction_value_count; r++) {
|
||||
sprintf(query, "INSERT INTO faction_values (char_id,faction_id,current_value)"
|
||||
" VALUES(%d,%d,%d)", charid, factions[r].faction_id, factions[r].current_value);
|
||||
if(mysql_query(&m, query) != 0) {
|
||||
printf("Unable to insert faction: %s\n", mysql_error(&m));
|
||||
return(1);
|
||||
}
|
||||
}
|
||||
|
||||
//inventory
|
||||
for(r = 0; r < header.inventory_count; r++) {
|
||||
sprintf(query, "INSERT INTO inventory (charid,slotid,itemid,charges,color,augslot1,augslot2,augslot3,augslot4,augslot5,instnodrop)"
|
||||
" VALUES(%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d)", charid,
|
||||
inventory[r].slotid, inventory[r].itemid, inventory[r].charges, inventory[r].colors,
|
||||
inventory[r].augs[0], inventory[r].augs[1], inventory[r].augs[2], inventory[r].augs[3],
|
||||
inventory[r].augs[4], inventory[r].instnodrop
|
||||
);
|
||||
if(mysql_query(&m, query) != 0) {
|
||||
printf("Unable to insert faction: %s\n", mysql_error(&m));
|
||||
return(1);
|
||||
}
|
||||
}
|
||||
|
||||
//shared bank
|
||||
//this is far from perfect since this is per-account, works great with empty shard bank...
|
||||
for(r = 0; r < header.sharedbank_count; r++) {
|
||||
sprintf(query, "INSERT INTO sharedbank (acctid,slotid,itemid,charges,augslot1,augslot2,augslot3,augslot4,augslot5)"
|
||||
" VALUES(%d,%d,%d,%d,%d,%d,%d,%d,%d)", accountid,
|
||||
sharedbank[r].slotid, sharedbank[r].itemid, sharedbank[r].charges,
|
||||
sharedbank[r].augs[0], sharedbank[r].augs[1], sharedbank[r].augs[2], sharedbank[r].augs[3], sharedbank[r].augs[4]
|
||||
);
|
||||
if(mysql_query(&m, query) != 0) {
|
||||
//ignore errors on insert
|
||||
printf("Shared bank warning: %s\n", mysql_error(&m));
|
||||
// return(1);
|
||||
}
|
||||
}
|
||||
|
||||
//quest globals
|
||||
for(r = 0; r < header.quest_globals_count; r++) {
|
||||
cursor = query;
|
||||
cursor += sprintf(cursor, "INSERT INTO quest_globals (charid,npcid,zoneid,name,value,expdate)"
|
||||
" VALUES(%d,%d,%d,'", charid, qglobals[r].npcid, qglobals[r].zoneid);
|
||||
cursor += mysql_real_escape_string(&m, cursor, (const char *) qglobals[r].name, strlen(qglobals[r].name));
|
||||
cursor += sprintf(cursor, "','");
|
||||
cursor += mysql_real_escape_string(&m, cursor, (const char *) qglobals[r].value, strlen(qglobals[r].value));
|
||||
sprintf(cursor, "',%d)", qglobals[r].expdate);
|
||||
|
||||
if(mysql_query(&m, query) != 0) {
|
||||
printf("Unable to insert quest global: %s\n", mysql_error(&m));
|
||||
return(1);
|
||||
}
|
||||
}
|
||||
|
||||
mysql_close(&m);
|
||||
|
||||
printf("Successfully imported %s as character id %d\n", header.name, charid);
|
||||
|
||||
return(0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user