added source folders

This commit is contained in:
purpleyouko committed 2025-08-11 11:09:09 -05:00
1 parent f23521f720
commit cfdc19df45
145 files changed
+54574

No files matched your search

+46
View File
@@ -0,0 +1,46 @@
/*
Rose Online Server Emulator
Copyright (C) 2006,2007 OSRose Team http://osroseon.to.md
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
depeloped with Main erose/hrose source server + some change from the original eich source
*/
#include "charserver.h"
// Constructor
CCharClient::CCharClient( )
{
userid = 0;
platinum = false;
memset( &username, '\0', 17 );
memset( &password, '\0', 33 );
memset( &charname, '\0', 17 );
accesslevel = 0;
channel = 0;
clanid = 0;
clan_rank = 0;
level = 0;
job = 0;
charid = 0;
isLoggedIn = false;
logout = false;
}
// Deconstructor
CCharClient::~CCharClient( )
{
}
+579
View File
@@ -0,0 +1,579 @@
/*
Rose Online Server Emulator
Copyright (C) 2006,2007 OSRose Team http://osroseon.to.md
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
developed with Main erose/hrose source server + some change from the original eich source
*/
#include "charserver.h"
// Do player identification
bool CCharServer::pakDoIdentify( CCharClient* thisclient, CPacket* P )
{
if (thisclient->isLoggedIn) return false;
MYSQL_RES *result;
MYSQL_ROW row;
thisclient->userid = GETDWORD((*P), 0x00);
memcpy( thisclient->password, &P->Buffer[4], 32 );
result = DB->QStore("SELECT username,lastsvr,accesslevel,platinum FROM accounts WHERE id=%i AND password='%s'", thisclient->userid, thisclient->password);
if(result==NULL) return false;
if (mysql_num_rows( result ) != 1)
{
Log( MSG_HACK, "Someone tried to connect to char server with an invalid account" );
DB->QFree( );
return false;
}
else
{
row = mysql_fetch_row(result);
strncpy_s (thisclient->username, row[0], 16);
thisclient->channel = atoi(row[1]);
thisclient->accesslevel = atoi(row[2]);
thisclient->platinum = atoi(row[3]);
DB->QFree( );
}
Log( MSG_INFO,"User '%s'(#%i) logged in", thisclient->username, thisclient->userid );
BEGINPACKET( pak, 0x070c );
ADDBYTE ( pak, 0 );
ADDDWORD ( pak, 0x87654321);
ADDDWORD ( pak, 0x00000000 );
thisclient->SendPacket( &pak );
result = DB->QStore( "SELECT online FROM accounts WHERE username='%s'", thisclient->username );
if(result==NULL) return false;
row = mysql_fetch_row(result);
bool online = atoi(row[0]);
DB->QFree( );
if(online)
return false;
if(!DB->QExecute( "UPDATE accounts SET online=1 WHERE username='%s'", thisclient->username ))
return false;
thisclient->isLoggedIn = true;
thisclient->returnedfromWS=false;
return true;
}
// Get this clients character list
bool CCharServer::pakGetCharacters( CCharClient* thisclient, CPacket* P )
{
if (!thisclient->isLoggedIn) return false;
// Properly delete items, quests, friends when deleting a character
// Hooray for joins.
MYSQL_RES *result;
MYSQL_ROW row;
DB->QExecute( "DELETE FROM characters, items, list_friend, list_quest USING characters LEFT JOIN items ON items.owner = characters.id LEFT JOIN list_friend \
ON (list_friend.id = characters.id OR list_friend.idfriend = characters.id) LEFT JOIN list_quest ON list_quest.owner = characters.id WHERE (characters.deletetime > 0 AND characters.deletetime <= %i)", GetServerTime( ) );
CItem items[10];
unsigned int charnum=0;
CCharacter chars[5];
// 0 1 2 3 4 5 6 7
result = DB->QStore("SELECT char_name,level,face,hairStyle,sex,classid,id,deletetime FROM characters WHERE account_name='%s'", thisclient->username);
if(result==NULL) return false;
while (row = mysql_fetch_row(result))
{
strcpy( chars[charnum].char_name , row[0] );
chars[charnum].level = atoi(row[1]);
chars[charnum].face = atoi(row[2]);
chars[charnum].hairStyle = atoi(row[3]);
chars[charnum].sex = atoi(row[4]);
chars[charnum].classid = atoi(row[5]);
chars[charnum].id = atoi(row[6]);
chars[charnum].DeleteTime = atoi(row[7]);
if(chars[charnum].DeleteTime > 0)
{
chars[charnum].DeleteTime = chars[charnum].DeleteTime - GetServerTime( );
}
charnum++;
}
DB->QFree( );
BEGINPACKET( pak, 0x0712 );
ADDBYTE ( pak, charnum );
for (unsigned k=0;k<charnum;k++)
{
for(unsigned j=0; j<10; j++)
ClearItem( items[j] );
// 0 1 2 3 4 5
//result = DB->QStore("SELECT itemnum,itemtype,refine,durability,lifespan,slotnum FROM items WHERE owner=%i AND slotnum<10", chars[k].id);
result = DB->QStore("SELECT itemid, itemtype, refine, durability, lifespan FROM charitems WHERE owner=%i", chars[k].id);
if(result == NULL) return false;
char *tmpid;
char *itmp;
while( row = mysql_fetch_row(result) )
{
tmpid = strtok( row[0] , "|");
for(unsigned int i=1;i<10; i++)
{
if((tmpid = strtok( NULL , "|"))!= NULL)
{
items[i].itemnum = atoi(tmpid);
}
}
tmpid = strtok( row[1] , "|");
for(unsigned int i=1;i<10; i++)
{
if((tmpid = strtok( NULL , "|"))!= NULL)
{
items[i].itemtype = atoi(tmpid);
}
}
tmpid = strtok( row[2] , "|");
for(unsigned int i=1;i<10; i++)
{
if((tmpid = strtok( NULL , "|"))!= NULL)
{
items[i].refine = atoi(tmpid);
}
}
tmpid = strtok( row[3] , "|");
for(unsigned int i=1;i<10; i++)
{
if((tmpid = strtok( NULL , "|"))!= NULL)
{
items[i].durability = atoi(tmpid);
}
}
tmpid = strtok( row[4] , "|");
for(unsigned int i=1;i<10; i++)
{
if((tmpid = strtok( NULL , "|"))!= NULL)
{
items[i].lifespan = atoi(tmpid);
}
}
}
/*
while(row = mysql_fetch_row(result))
{
unsigned itemnum = atoi(row[5]);
items[itemnum].itemnum = atoi(row[0]);
items[itemnum].itemtype = atoi(row[1]);
items[itemnum].refine = atoi(row[2]);
items[itemnum].durability = atoi(row[3]);
items[itemnum].lifespan = atoi(row[4]);
}*/
DB->QFree( );
ADDSTRING ( pak, chars[k].char_name );
ADDBYTE ( pak, 0x00 );
ADDBYTE ( pak, chars[k].sex ); // SEX
ADDWORD ( pak, chars[k].level ); // LEVEL
ADDWORD ( pak, chars[k].classid ); // CLASSID
ADDDWORD ( pak, chars[k].DeleteTime ); // DELETE TIME
ADDBYTE ( pak, 0x00 );//thisclient->platinum?0x01:0x00 ); // IS PLATINUM? 00-NO;01-YES;02-YES BUT USER IS NOT
ADDDWORD ( pak, chars[k].face ); // FACE
ADDDWORD ( pak, chars[k].hairStyle ); // HAIR
ADDWORD ( pak, items[2].itemnum ); // CAP
ADDWORD ( pak, items[2].refine ); // CAP REFINE
ADDWORD ( pak, items[3].itemnum ); // BODY
ADDWORD ( pak, items[3].refine ); // BODY REFINE
ADDWORD ( pak, items[5].itemnum ); // GLOVES
ADDWORD ( pak, items[5].refine ); // GLOVES REFINE
ADDWORD ( pak, items[6].itemnum ); // BOOTS
ADDWORD ( pak, items[6].refine ); // BOOTS REFINE
ADDWORD ( pak, items[1].itemnum ); // FACE
ADDWORD ( pak, items[1].refine ); // FACE REFINE
ADDWORD ( pak, items[4].itemnum ); // BACK
ADDWORD ( pak, items[4].refine ); // BACK REFINE
ADDWORD ( pak, items[7].itemnum ); // WEAPON
ADDWORD ( pak, items[7].refine ); // WEAPON REFINE
ADDWORD ( pak, items[8].itemnum ); // SUBWEAPON
ADDWORD ( pak, items[8].refine ); // SUBWEAPON REFINE
}
thisclient->SendPacket( &pak );
return true;
}
// Send away the world IP
bool CCharServer::pakRequestWorld( CCharClient* thisclient, CPacket* P )
{
if (!thisclient->isLoggedIn) return false;
MYSQL_ROW row;
MYSQL_RES *result;
memcpy( thisclient->charname, &P->Buffer[3], P->Size-6-4 );
thisclient->charname[P->Size-6-4] = 0;
Log( MSG_INFO,"User %s(%i) selected char '%s'", thisclient->username, thisclient->userid, thisclient->charname);
if(!DB->QExecute("UPDATE accounts SET lastchar='%s' WHERE id=%i", thisclient->charname, thisclient->userid))
return false;
result = DB->QStore("SELECT host,port FROM channels WHERE id=%i", thisclient->channel);
if(result==NULL) return false;
if(mysql_num_rows( result )!=1 )
{
Log( MSG_WARNING, "Invalid Server: %i", thisclient->channel );
DB->QFree( );
return false;
}
row = mysql_fetch_row( result );
BEGINPACKET( pak, 0x711 );
ADDWORD ( pak, atoi(row[1]) ); // PORT
ADDDWORD ( pak, thisclient->userid );
ADDDWORD ( pak, 0x87654321 );
ADDSTRING ( pak, row[0] );//IP
ADDBYTE ( pak, 0 );
thisclient->SendPacket( &pak );
DB->QFree( );
//CHAR INFORMATION 0 1 2 3 4
result = DB->QStore("SELECT clanid,clan_rank,id,level,classid FROM characters WHERE char_name='%s'", thisclient->charname);
if(result==NULL) return false;
if(mysql_num_rows(result)!=1)
{
Log( MSG_WARNING, "Number of user with charname '%s' is %i", thisclient->charname,mysql_num_rows(result));
DB->QFree( );
return false;
}
row = mysql_fetch_row( result );
thisclient->clanid = atoi( row[0] );
thisclient->clan_rank = atoi( row[1] );
thisclient->charid = atoi( row[2] );
thisclient->level = atoi( row[3] );
thisclient->job = atoi( row[4] );
DB->QFree( );
//MESSENGER INFORMATION
// // 0 1
result = DB->QStore("SELECT idfriend,namefriend FROM list_friend WHERE id=%i", thisclient->charid);
if(result==NULL) return false;
BYTE nfriends = mysql_num_rows(result) & 0xff;
RESETPACKET( pak, 0x7e1 );// Friend list command
ADDBYTE ( pak, 0x06 );// Sending Friend List
ADDBYTE ( pak, nfriends );// # friends
while(row = mysql_fetch_row( result ))
{
CFriendList * newfriend = new CFriendList;
assert(newfriend);
newfriend->id = atoi(row[0]); //friendid
strcpy(newfriend->name, row[1]); //friend name
thisclient->FriendList.push_back( newfriend );
ADDWORD (pak, newfriend->id);// friend id
ADDWORD (pak, 0x0000 );
CCharClient* otherclient = (CCharClient*) GetClientByID( newfriend->id );
if(otherclient!=NULL) //is online??
{
ADDBYTE (pak, 0x07 ); //online
ChangeMessengerStatus ( thisclient, otherclient, 0x07);
}
else
{
ADDBYTE (pak, 0x08 );//offline
}
ADDSTRING (pak, newfriend->name); //friend name
ADDBYTE (pak, 0x00 );
}
thisclient->SendPacket( &pak );
DB->QFree( );
thisclient->logout = false;
//SEND CLAN INFORMATION
SendClanInfo (thisclient);
return true;
}
// Create a character
bool CCharServer::pakCreateChar( CCharClient* thisclient, CPacket* P )
{
if (!thisclient->isLoggedIn) return false;
// Get info from packet
unsigned sex = GETBYTE((*P), 0 ) % 2;
unsigned hairstyle = GETBYTE((*P), 2 );
unsigned face = GETBYTE((*P), 3 );
string newname = (char*)&P->Buffer[7];
MYSQL_RES *result;
result = DB->QStore("SELECT id FROM characters WHERE account_name='%s'", thisclient->username);
if(result==NULL) return false;
if ( mysql_num_rows( result ) == 5 )
{
STARTPACKET( pak, 0x0713, 8 );
SETWORD ( pak, 0x00, 4 )
thisclient->SendPacket( &pak );
DB->QFree( );
return true;
}
DB->QFree( );
result = DB->QStore("SELECT id FROM characters WHERE char_name='%s'", newname.c_str());
if(result==NULL) return false;
if ( mysql_num_rows( result ) > 0 )
{
STARTPACKET( pak, 0x0713, 8 );
SETWORD ( pak, 0x00, 2 );
thisclient->SendPacket( &pak );
DB->QFree( );
return true;
}
DB->QFree( );
if(!DB->QExecute("INSERT INTO characters (account_name, char_name, face, hairStyle, sex) VALUES('%s','%s',%i,%i,%i)", thisclient->username, newname.c_str(), face, hairstyle, sex))
return false;
unsigned int mid = (unsigned)mysql_insert_id( DB->Mysql );
MYSQL_ROW row;
char tmp1[1024] = ""; //itemid
char tmp2[1024] = ""; //itemtype
char tmp3[1024] = ""; //refine
char tmp4[1024] = ""; //durability
char tmp5[1024] = ""; //lifespan
char tmp6[1024] = ""; //count
char tmp7[1024] = ""; //stats
char tmp8[1024] = ""; //socketed
char tmp9[1024] = ""; //appraised
sprintf(&tmp2[strlen(tmp2)], "0|0|0|3|0|0|0|8|0|0|0|0|2|0");
sprintf(&tmp3[strlen(tmp3)], "0|0|0|0|0|0|0|0|0|0|0|0|0|0");
sprintf(&tmp4[strlen(tmp4)], "0|0|0|40|0|0|0|40|0|0|0|0|40|0");
sprintf(&tmp5[strlen(tmp5)], "0|0|0|100|0|0|0|100|0|0|0|0|100|0");
sprintf(&tmp6[strlen(tmp6)], "0|0|0|1|0|0|0|1|0|0|0|0|1|0");
sprintf(&tmp7[strlen(tmp7)], "0|0|0|0|0|0|0|0|0|0|0|0|0|0");
sprintf(&tmp8[strlen(tmp8)], "0|0|0|0|0|0|0|0|0|0|0|0|0|0");
sprintf(&tmp9[strlen(tmp9)], "0|0|0|1|0|0|0|1|0|0|0|0|1|0");
int tran = 1;
//if(!DB->QExecute("INSERT INTO items VALUES(%i,30,3,0,40,100,3,1,0,0,0,0)", mid))
// return false;
//if(!DB->QExecute("INSERT INTO items VALUES(%i,1,8,0,40,100,7,1,0,0,0,0)", mid))
// return false;
if(sex==0)
{
//if(!DB->QExecute("INSERT INTO items VALUES(%i,222,2,0,40,100,12,1,0,0,0,0)", mid))
// return false;
sprintf(&tmp1[strlen(tmp1)], "0|0|0|30|0|0|0|1|0|0|0|0|222|0");
if(!DB->QExecute("INSERT INTO charitems (owner,itemid,itemtype,refine,durability,lifespan,count,stats,socketed,appraised,trans_action) VALUES('%i','%s','%s','%s','%s','%s','%s','%s','%s','%s','%i')",
mid,tmp1,tmp2,tmp3,tmp4,tmp5,tmp6,tmp7,tmp8,tmp9,tran))
return false;
}
else
{
//if(!DB->QExecute("INSERT INTO items VALUES(%i,221,2,0,40,100,12,1,0,0,0,0)", mid))
// return false;
sprintf(&tmp1[strlen(tmp1)], "0|0|0|30|0|0|0|1|0|0|0|0|221|0");
if(!DB->QExecute("INSERT INTO charitems (owner,itemid,itemtype,refine,durability,lifespan,count,stats,socketed,appraised,trans_action) VALUES('%i','%s','%s','%s','%s','%s','%s','%s','%s','%s','%i')",
mid,tmp1,tmp2,tmp3,tmp4,tmp5,tmp6,tmp7,tmp8,tmp9,tran))
return false;
}
STARTPACKET( pak, 0x0713, 8 );
SETWORD ( pak, 0x00, 0 );
thisclient->SendPacket( &pak );
return true;
}
// Connect WorldServer
bool CCharServer::pakWSReady ( CCharClient* thisclient, CPacket* P )
{
if(thisclient->isLoggedIn) return false;
if(GETDWORD((*P),0) != Config.CharPass )
{
Log( MSG_HACK, "WorldServer Tried to connect CharServer with wrong password ");
return true;
}
thisclient->userid = GETDWORD((*P), 4); //our channelid
thisclient->accesslevel = 0xffff; //this will identify thisclient as channel
// add channel
CChanels* newchannel = new (nothrow) CChanels;
if(newchannel==NULL)
return false;
newchannel->id = GETDWORD((*P), 4);
newchannel->ip = inet_ntoa( thisclient->clientinfo.sin_addr );
newchannel->port = GETWORD((*P),8 );
Log( MSG_INFO, "Channel #%i connected from ip %s", newchannel->id, newchannel->ip );
// Connect to charserver
newchannel->sock = socket( AF_INET, SOCK_STREAM, 0 );
if (newchannel->sock == INVALID_SOCKET)
{
Log( MSG_WARNING, "Could not access worldserver IP: %s , Port: %i", newchannel->ip, newchannel->port );
delete newchannel;
return false;
}
struct sockaddr_in ain;
ain.sin_family = AF_INET;
ain.sin_addr.s_addr = inet_addr(newchannel->ip);
ain.sin_port = htons( newchannel->port );
memset(&(ain.sin_zero), '\0', 8);
if ( connect( newchannel->sock , (SOCKADDR*) &ain, sizeof(ain) ) == SOCKET_ERROR)
{
Log( MSG_WARNING, "Could not access worldserver IP: %s , Port: %i", newchannel->ip , newchannel->port );
delete newchannel;
return false;
}
ChannelList.push_back( newchannel );
thisclient->isLoggedIn = true;
BEGINPACKET( pak, 0x500 );
ADDDWORD ( pak, Config.WorldPass );
//cryptPacket( (char*)&pak, NULL );
//EncryptBuffer( CryptTable,(unsigned char*)&pak );
Log( MSG_INFO, "Accessing worldserver IP: %s , Port: %i", newchannel->ip , newchannel->port );
send( newchannel->sock, (char*)&pak, pak.Size, 0 );
return true;
}
// Login Connected
bool CCharServer::pakLoginConnected( CCharClient* thisclient, CPacket* P )
{
if(thisclient->isLoggedIn) return false;
if(GETDWORD((*P),0) != Config.CharPass )
{
Log( MSG_HACK, "LoginServer Tried to connect CharServer with wrong password ");
return true;
}
thisclient->isLoggedIn = true;
return true;
}
// Return to char select
bool CCharServer::pakWSCharSelect ( CCharClient* thisclient, CPacket* P )
{
//if(!thisclient->isLoggedIn) return false;
Log( MSG_INFO, "World server requested char select" );
unsigned int userid = GETDWORD( (*P), 0 );
CCharClient* otherclient = GetClientByUserID( userid );
if(otherclient==NULL)
{
Log(MSG_WARNING, "Invalid userid: %i", userid );
return true;
}
BEGINPACKET( pak, 0x71c );
//ADDBYTE ( pak, 0x00 );
otherclient->SendPacket( &pak );
Log( MSG_INFO, "Client returning to char select" );
return true;
}
// ???
bool CCharServer::pak7e5 ( CCharClient* thisclient, CPacket* P )
{
BEGINPACKET( pak, 0 );
if(!thisclient->isLoggedIn) return false;
unsigned int action = GETBYTE((*P),0);
switch(action)
{
case 0x03:
RESETPACKET( pak, 0x7e5 );
ADDBYTE ( pak, 0x01 );
ADDWORD ( pak, 0x0000 );
thisclient->SendPacket( &pak );
break;
default:
Log( MSG_WARNING,"Unknown 7e5 action %i",action);
}
return true;
}
// Create a chatroom?
bool CCharServer::pakChatrooms ( CCharClient* thisclient, CPacket* P )
{
if(!thisclient->isLoggedIn) return false;
return true;
}
// delete/resurect character
bool CCharServer::pakDeleteChar( CCharClient* thisclient, CPacket* P )
{
if(!thisclient->isLoggedIn) return false;
short int action = GETBYTE((*P), 1 );
unsigned long int DeleteTime = 0;
switch(action)
{
case 0x00://Resurect
{
DeleteTime = 0;
if(!DB->QExecute(" UPDATE characters SET deletetime=0 WHERE char_name='%s'",
(char*)&P->Buffer[2] ))
return false;
}
break;
case 0x01://Delete
{
DeleteTime = GetServerTime( ) + Config.DeleteTime;
if(!DB->QExecute(" UPDATE characters SET deletetime=%i WHERE char_name='%s'",
DeleteTime, (char*)&P->Buffer[2] ))
return false;
}
break;
}
BEGINPACKET( pak, 0x714 );
if(DeleteTime > 0 )
{
ADDDWORD ( pak, Config.DeleteTime );
}
else
{
ADDDWORD ( pak, 0x00000000 );
}
ADDSTRING ( pak, (char*)&P->Buffer[2] );
ADDBYTE ( pak, 0x00 );
thisclient->SendPacket( &pak );
return true;
}
bool CCharServer::pakUpdateLevel( CCharClient* thisclient, CPacket* P )
{
if(!thisclient->isLoggedIn) return false;
WORD charid = GETWORD((*P),0);
WORD level = GETWORD((*P),2);
for(UINT i=0;i<ClientList.size();i++)
{
CCharClient* player = (CCharClient*) ClientList.at(i);
if(player->charid==charid)
{
player->level = level;
break;
}
}
return true;
}
// Disconnect client from char/world server
bool CCharServer::pakLoginDSClient( CCharClient* thisclient, CPacket* P )
{
if(!thisclient->isLoggedIn) return false;
BYTE action = GETBYTE((*P),0);
switch(action)
{
case 1:
{
unsigned int userid = GETDWORD ((*P), 1);
CCharClient* otherclient = GetClientByUserID( userid );
if(otherclient==NULL)
{
Log( MSG_WARNING, "Userid '%u' is not online", userid );
return true;
}
otherclient->isLoggedIn = false;
otherclient->isActive = false;
BEGINPACKET( pak, 0x502 );
ADDBYTE ( pak, 1 );
ADDDWORD ( pak, userid );
ADDBYTE ( pak, 0x00 );
CChanels* thischannel = GetChannelByID( otherclient->channel );
if(thischannel!=NULL){
send( thischannel->sock, (char*)&pak, pak.Size, 0 );}
else { Log(MSG_ERROR, "Check serverid in worldserver.conf it should be the same as ID in channels in the mysql database %i",thisclient->channel);}
}
break;
}
return true;
}
+204
View File
@@ -0,0 +1,204 @@
/*
Rose Online Server Emulator
Copyright (C) 2006,2007 OSRose Team http://osroseon.to.md
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
depeloped with Main erose/hrose source server + some change from the original eich source
*/
#include "charserver.h"
// Constructor
CCharServer::CCharServer( string fn )
{
LoadConfigurations( (char*)fn.c_str() );
GServer = this;
}
// Deconstructor
CCharServer::~CCharServer( )
{
}
// Return a new clientsocket structure
CCharClient* CCharServer::CreateClientSocket( )
{
CCharClient* thisclient = new (nothrow) CCharClient( );
return thisclient;
}
//loadserver encryption
void CCharServer::LoadEncryption( )
{
GenerateCryptTables( CryptTable, 0x87654321 );
}
// When Server is ready
bool CCharServer::OnServerReady( )
{
DB->QExecute( "DELETE FROM channels WHERE id=%u", Config.ServerID);
if(!DB->QExecute("INSERT INTO channels (id,name,host,port,connected,maxconnections,owner) VALUES (%i,'%s','%s',%i,0,%i,%i)",
Config.ServerID, Config.ServerName, Config.CharIP, Config.CharPort, Config.MaxConnections, Config.ParentID))
{
Log(MSG_WARNING, "Error accessing to database, the other server will not connect to CharServer" );
}
MYSQL_RES *result;
MYSQL_ROW row;
// Load all our clans
result = DB->QStore("SELECT id,logo,back,name,cp,grade,slogan,news FROM list_clan");
if(result==NULL) return false;
while(row = mysql_fetch_row(result))
{
CClans* thisclan = new CClans;
assert(thisclan); // maybe remove
thisclan->id = atoi(row[0]);
thisclan->logo = atoi(row[1]);
thisclan->back = atoi(row[2]);
strcpy(thisclan->name,row[3]);
thisclan->cp = atoi(row[4]);
thisclan->grade = atoi(row[5]);
strcpy(thisclan->slogan,row[6]);
strcpy(thisclan->news,row[7]);
ClanList.push_back( thisclan );
}
DB->QFree( );
// Load Clans
for(UINT i=0;i<ClanList.size( );i++)
{
CClans* Clan = ClanList.at( i );
result = DB->QStore("SELECT id,char_name,clan_rank FROM characters WHERE clanid=%i order by clan_rank",Clan->id);
if(result==NULL) return false;
while(row = mysql_fetch_row(result))
{
CClanMembers* newmember = new CClanMembers;
assert(newmember);
newmember->id = atoi(row[0]);
strcpy(newmember->name,row[1]);
newmember->clan_rank = atoi(row[2]);
Clan->ClanMembers.push_back( newmember );
}
DB->QFree( );
}
Log( MSG_INFO, "Clans Information Loaded" );
return true;
}
// When a a client is disconnected
void CCharServer::OnClientDisconnect( CClientSocket* thisclient )
{
CCharClient* thisclientwc = (CCharClient*)thisclient;
DB->QExecute( "UPDATE accounts SET online=0 WHERE username='%s'", thisclientwc->username );
if(!thisclientwc->logout)
{
// Send logout message to friends
for(UINT i=0;i<thisclientwc->FriendList.size( );i++)
{
CFriendList* Friend = thisclientwc->FriendList.at( i );;
CCharClient* otherclient = GetClientByID( Friend->id );
if(otherclient!=NULL)
{
ChangeMessengerStatus ( thisclientwc, otherclient, 0x08);
}
}
//set logout messga to clan
CClans* thisclan = GetClanByID(thisclientwc->clanid);
if(thisclan==NULL)
return;
for(UINT i=0;i<thisclan->ClanMembers.size( );i++)
{
CClanMembers* ClanMember = thisclan->ClanMembers.at( i );
CCharClient* otherclient = GetClientByID( ClanMember->id );
if(otherclient!=NULL)
ChangeClanStatus (thisclientwc, otherclient, 0xff);
}
}
}
// Deletes an old clientsocket structure
void CCharServer::DeleteClientSocket( CClientSocket* thisclient )
{
if (thisclient->isserver)
Log( MSG_INFO, "Server disconnected" );
else
Log( MSG_INFO, "User disconnected" );
delete (CCharClient*)thisclient;
}
// Load Server configuration
void CCharServer::LoadConfigurations( const char* file )
{
//Database
Config.SQLServer.pcServer = ConfigGetString ( file, "mysql_host", "localhost" );
Config.SQLServer.pcDatabase = ConfigGetString ( file, "mysql_database", "roseon_beta" );
Config.SQLServer.pcUserName = ConfigGetString ( file, "mysql_user", "root" );
Config.SQLServer.pcPassword = ConfigGetString ( file, "mysql_pass", "" );
Config.SQLServer.pcPort = ConfigGetInt ( file, "mysql_port", 3306 );
//Server
Config.ServerID = ConfigGetInt ( file, "serverid", 1 );
Config.ServerType = 1; // Char always = 1
Config.CharIP = ConfigGetString ( file, "serverip", "127.0.0.1" );
Config.CharPort = ConfigGetInt ( file, "serverport", 29100 );
Config.ParentID = ConfigGetInt ( file, "parentid", 0 );
Config.ServerName = ConfigGetString ( file, "servername", "Server" );
Config.CharsPort = ConfigGetInt ( file, "CharsPort", 29110 );
//Char
Config.usethreads = ConfigGetInt ( file, "usethreads", 0 )==0?false:true;
Config.DeleteTime = ConfigGetInt ( file, "deletetime", 36000 );
Config.MinimumAccessLevel = ConfigGetInt ( file, "accesslevel", 100 );
//Password
Config.LoginPass = ConfigGetInt ( file, "loginpass", 123456 );
Config.CharPass = ConfigGetInt ( file, "charpass", 123456 );
Config.WorldPass = ConfigGetInt ( file, "worldpass", 123456 );
}
// Incoming packet
bool CCharServer::OnReceivePacket( CClientSocket* thisclient, CPacket *P )
{
Log(MSG_INFO,"Packet received at OnReceivePacket");
switch( P->Command )
{
case 0x0500: return pakWSReady ( (CCharClient*)thisclient, P );
case 0x0501: return pakLoginConnected ( (CCharClient*)thisclient, P );
case 0x0502: return pakLoginDSClient ( (CCharClient*)thisclient, P );
case 0x0505: return pakWSCharSelect ( (CCharClient*)thisclient, P );
case 0x070b: return pakDoIdentify ( (CCharClient*)thisclient, P );
case 0x0712: return pakGetCharacters ( (CCharClient*)thisclient, P );
case 0x0713: return pakCreateChar ( (CCharClient*)thisclient, P );
case 0x0714: return pakDeleteChar ( (CCharClient*)thisclient, P );
case 0x0715: return pakRequestWorld ( (CCharClient*)thisclient, P );
case 0x0787: return pakClanChat ( (CCharClient*)thisclient, P );
case 0x07e0: return pakClanManager ( (CCharClient*)thisclient, P );
case 0x07e1: return pakMessengerManager ( (CCharClient*)thisclient, P );
case 0x07e2: return pakMessengerChat ( (CCharClient*)thisclient, P );
case 0x07e3: return pakChatrooms ( (CCharClient*)thisclient, P );
case 0x07e5: return pak7e5 ( (CCharClient*)thisclient, P );
case 0x07e6: return pakUploadCM ( (CCharClient*)thisclient, P );
case 0x07e7: return pakDownloadCM ( (CCharClient*)thisclient, P );
case 0x07e8: return pakClanIconTime ( (CCharClient*)thisclient, P );
case 0x079e: return pakUpdateLevel ( (CCharClient*)thisclient, P );
default:
Log( MSG_WARNING, "(SID:%i) Received unknown packet. Command:%04x Size:%04x", thisclient->sock, P->Command, P->Size );
break;
}
return true;
}
bool CCharServer::Ping( )
{
return DB->Ping( );
}
+115
View File
@@ -0,0 +1,115 @@
/*
Open Source Rose Online Team - http://osroseon.to.md/
note: the Server is develop with erose source server + eich source
*/
#ifndef __ROSE_SERVERS__
#define __ROSE_SERVERS__
#include <time.h>
#include "../common/sockets.h"
#include "datatypes.h"
#define ClearItem(i) { i.durability=0; i.itemnum=0; i.itemtype=0; i.lifespan=0; i.refine=0; }
using namespace std;
// Clent class
class CCharClient : public CClientSocket
{
public:
CCharClient ( ); // constructor
~CCharClient ( ); // destructor
// User information
UINT userid;
bool platinum;
char username[17];
char password[33];
UINT accesslevel;
UINT channel;
// Character information
char charname[17];
UINT clanid;
int clan_rank;
UINT level;
UINT job;
UINT charid;
bool isLoggedIn;
bool returnedfromWS;
bool logout;
vector<CFriendList*> FriendList;
};
// Server class
class CCharServer : public CServerSocket
{
public:
CCharServer ( string );
~CCharServer( );
CCharClient* CreateClientSocket( );
void DeleteClientSocket( CClientSocket* thisclient );
void LoadEncryption( );
void OnClientDisconnect( CClientSocket* thisclient );
bool OnServerReady( );
void LoadConfigurations( const char* );
bool OnReceivePacket( CClientSocket* thisclient, CPacket* P );
bool Ping( );
// Extra functions
CChanels* GetChannelByID( UINT id );
CCharClient* GetClientByUserID( UINT id );
CCharClient* GetClientByID( UINT id );
CCharClient* GetClientByName( char *name );
CCharClient* GetClientByUserName( char *username );
CClans* GetClanByID( int id );
unsigned long int GetServerTime( );
// Community functions
bool ChangeMessengerStatus (CCharClient* thisclient, CCharClient* otherclient, int status);
bool pakMessengerManager ( CCharClient* thisclient, CPacket* P );
bool pakMessengerChat ( CCharClient* thisclient, CPacket* P );
// Clan Functions
bool SendClanInfo (CCharClient* thisclient);
bool ChangeClanStatus (CCharClient* thisclient, CCharClient* otherclient, int channel);
bool SendToClanMembers( int clanid,CPacket* pak );
bool UpdateClanWindow( int clanid );
bool pakClanMembers ( CCharClient* thisclient );
bool pakClanManager ( CCharClient* thisclient, CPacket* P );
bool pakClanChat ( CCharClient* thisclient, CPacket* P );
bool ClanLogout ( CCharClient* thisclient );
bool pakUploadCM ( CCharClient* thisclient, CPacket* P );
bool pakDownloadCM( CCharClient* thisclient, CPacket* P );
bool pakClanIconTime( CCharClient* thisclient, CPacket* P );
// General Packets
bool pakUpdateLevel( CCharClient* thisclient, CPacket* P );
bool pakDoIdentify( CCharClient* thisclient, CPacket* P );
bool pakGetCharacters( CCharClient* thisclient, CPacket* P );
bool pakRequestWorld( CCharClient* thisclient, CPacket* P );
bool pakCreateChar( CCharClient* thisclient, CPacket* P );
bool pakDeleteChar( CCharClient* thisclient, CPacket* P );
bool pakWSReady ( CCharClient* thisclient, CPacket* P );
bool pakWSCharSelect ( CCharClient* thisclient, CPacket* P );
bool pakLoginConnected ( CCharClient* thisclient, CPacket* P );
bool pakLoginDSClient( CCharClient* thisclient, CPacket* P );
bool pak7e5 ( CCharClient* thisclient, CPacket* P );
bool pakChatrooms ( CCharClient* thisclient, CPacket* P );
// Variables
string filename;
vector <CClans*> ClanList;
vector <CChanels*> ChannelList;
//Login
SOCKET lsock; // Socket to Login
char* lct; // Encryption table for login server
CDatabase* DB;
};
void StartSignal( );
void StopSignal( );
void HandleSignal( int num );
extern class CCharServer* GServer;
#endif
File diff suppressed because it is too large. Load diff
+215
View File
@@ -0,0 +1,215 @@
/*
Rose Online Server Emulator
Copyright (C) 2006,2007 OSRose Team http://osroseon.to.md
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
depeloped with Main erose/hrose source server + some change from the original eich source
*/
#include "charserver.h"
// Change messenger status 07 - online | 08 - offline
bool CCharServer::ChangeMessengerStatus (CCharClient* thisclient, CCharClient* otherclient, int status)
{
BEGINPACKET( pak, 0x7e1 );
ADDBYTE ( pak, 0x08 );
ADDWORD ( pak, thisclient->charid );
ADDWORD ( pak, 0x0000 );
ADDBYTE ( pak, status );
otherclient->SendPacket(&pak);
return true;
}
// Messenger actions (add/remove/invite)
bool CCharServer::pakMessengerManager ( CCharClient* thisclient, CPacket* P )
{
BYTE action = GETBYTE((*P),0);
switch (action)
{
case 0x01://wanna be my friend?
{
char* nick = new (nothrow) char[P->Size];
if(nick==NULL)
{
Log(MSG_ERROR, "Error allocing memory: pakMessengerManager 1" );
return false;
}
memcpy( nick, &P->Buffer[1], P->Size );
CCharClient* otherclient = (CCharClient*) GetClientByName (nick);
if(otherclient!=NULL)
{//Send friend invitation (check this one)
BEGINPACKET( pak, 0x7e1 );
ADDBYTE ( pak, 0x01 );
ADDWORD ( pak, 0x0000 );
ADDSTRING ( pak, thisclient->charname );
ADDBYTE ( pak, 0x00 );
otherclient->SendPacket(&pak);
}
else
{//This charname doesnt exist
BEGINPACKET( pak, 0x7e1 );
ADDBYTE ( pak, 0x04 );
ADDSTRING ( pak, nick );
ADDBYTE ( pak, 0x00 );
thisclient->SendPacket(&pak);
}
delete []nick;
}
break;
case 0x02://yes i want
{
char* nick = new (nothrow) char[P->Size];
if(nick==NULL)
{
Log(MSG_ERROR, "Error allocing memory: pakMessengerManager 2" );
return false;
}
memcpy( nick, &P->Buffer[3], P->Size );
CCharClient* otherclient = (CCharClient*) GetClientByName (nick);
if(otherclient!=NULL)
{
BEGINPACKET( pak, 0x7e1 );
ADDBYTE ( pak, 0x02 );
ADDWORD ( pak, thisclient->charid );
ADDBYTE ( pak, 0x00 );
ADDWORD ( pak, 0x0000 );
ADDSTRING ( pak, thisclient->charname );
ADDBYTE ( pak, 0x00);
otherclient->SendPacket(&pak);
//Add friend to my friend list(sql)
if(!DB->QExecute("INSERT INTO list_friend (id,idfriend,namefriend) VALUES (%i,%i,'%s')",
otherclient->charid,thisclient->charid,thisclient->charname))
return false;
CFriendList * newfriend1 = new (nothrow) CFriendList;
if(newfriend1==NULL)
return false;
newfriend1->id = otherclient->charid; //friendid
strcpy(newfriend1->name, otherclient->charname); //friend name
thisclient->FriendList.push_back( newfriend1 );
RESETPACKET( pak, 0x7e1 );
ADDBYTE ( pak, 0x02 );
ADDWORD ( pak, otherclient->charid );
ADDBYTE ( pak, 0x00 );
ADDWORD ( pak, 0x0000 );
ADDSTRING ( pak, otherclient->charname );
ADDBYTE ( pak, 0x00);
thisclient->SendPacket(&pak);
//Add me to his friend list (sql)
if(!DB->QExecute("INSERT INTO list_friend (id,idfriend,namefriend) VALUES (%i,%i,'%s')",
thisclient->charid,otherclient->charid,otherclient->charname))
return false;
CFriendList * newfriend2 = new (nothrow) CFriendList;
if(newfriend2==NULL)
return false;
newfriend2->id = thisclient->charid; //friendid
strcpy(newfriend2->name, thisclient->charname); //friend name
otherclient->FriendList.push_back( newfriend2 );
}
else//not founded
{
BEGINPACKET( pak, 0x7e1 );
ADDBYTE ( pak, 0x04 );
ADDWORD ( pak, 0x0000 );
ADDSTRING ( pak, nick );
ADDBYTE ( pak, 0x00 );
thisclient->SendPacket(&pak);
}
delete []nick;
}
break;
case 0x03://no, i dont want
{
char* nick = new (nothrow) char[P->Size];
if(nick==NULL)
{
Log(MSG_ERROR, "Error allocing memory: pakMessengerManager 3" );
return false;
}
memcpy( nick, &P->Buffer[3], P->Size );
CCharClient* otherclient = (CCharClient*) GetClientByName (nick);
if(otherclient!=NULL)
{
BEGINPACKET( pak, 0x7e1 );
ADDBYTE ( pak, 0x03 );
ADDSTRING ( pak, thisclient->charname );
ADDBYTE ( pak, 0x00);
otherclient->SendPacket(&pak);
}
else
{
BEGINPACKET( pak, 0x7e1 );
ADDBYTE ( pak, 0x04 );
ADDWORD ( pak, 0x0000 );
ADDSTRING ( pak, nick );
ADDBYTE ( pak, 0x00 );
thisclient->SendPacket(&pak);
}
}
break;
case 0x05://freakin later
{
WORD id = GETWORD ((*P),1);
if(!DB->QExecute("DELETE FROM list_friend WHERE id=%i and idfriend=%i",
thisclient->charid,id))
return false;
CCharClient* otherclient = (CCharClient*) GetClientByID(id);
if(otherclient!=NULL)
{
ChangeMessengerStatus ( thisclient, otherclient, 0x08);
}
}
break;
case 0xfa://messenger logout
{
WORD id = GETWORD ((*P),1);
CCharClient* ctherclient = (CCharClient*) GetClientByID(id);
if(ctherclient==NULL)
return true;
ctherclient->logout = true;
for(UINT i=0;i<ctherclient->FriendList.size();i++)
{
CFriendList* thisfriend = ctherclient->FriendList.at( i );
CCharClient* otherclient = (CCharClient*) GetClientByID( thisfriend->id );
if(otherclient!=NULL)
{
ChangeMessengerStatus ( ctherclient, otherclient, 0x08);
}
}
//Logout in clan
ClanLogout ( ctherclient );
}
break;
default:
Log( MSG_INFO, "Friend action unknown: %i", action );
break;
}
return true;
}
// Messenger Chat
bool CCharServer::pakMessengerChat ( CCharClient* thisclient, CPacket* P )
{
WORD id = GETWORD((*P),0);
CCharClient* otherclient = (CCharClient*) GetClientByID(id);
if(otherclient!=NULL)
{
BEGINPACKET( pak, 0x7e2 );
ADDWORD ( pak, thisclient->charid );
for (int i=2;i<(P->Size-6);i++)
ADDBYTE ( pak, GETBYTE((*P),i ));
otherclient->SendPacket(&pak);
}
return true;
}
+68
View File
@@ -0,0 +1,68 @@
/*
Open Source Rose Online Team - http://osroseon.to.md/
note: the Server is develop with erose source server + eich source
*/
#ifndef __ROSE_DATATYPES__
#define __ROSE_DATATYPES__
#include "../common/sockets.h"
// List of clan members
struct CClanMembers
{
UINT id;
char name[50];
int clan_rank;
};
// An item (for figuring out what a user is wearing)
struct CItem {
UINT owner;
UINT itemnum;
UINT itemtype;
UINT refine;
UINT durability;
UINT lifespan;
};
// A single client character
struct CCharacter {
char char_name[17];
UINT level;
UINT face;
UINT hairStyle;
int sex;
UINT classid;
UINT id;
unsigned long int DeleteTime;
};
// List of friends
struct CFriendList
{
int id;
char name[17];
};
// List of clan
struct CClans
{
int id;
int logo;
int back;
int grade;
int cp;
char name[17];
char slogan[30];
char news[260];
vector<CClanMembers*> ClanMembers;
};
// Channel list
struct CChanels
{
UINT id;
char* ip;
UINT port;
SOCKET sock;
};
#endif
+184
View File
@@ -0,0 +1,184 @@
/*
Rose Online Server Emulator
Copyright (C) 2006,2007 OSRose Team http://osroseon.to.md
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
depeloped with Main erose/hrose source server + some change from the original eich source
*/
#include "charserver.h"
// Search client by userid
CCharClient* CCharServer::GetClientByUserID( UINT userid )
{
for(UINT i=0;i<ClientList.size( );i++)
{
CCharClient* client = (CCharClient*) ClientList.at( i );
if(client->userid==userid)
{
return client;
}
}
return NULL;
}
// Search the client by char id
CCharClient* CCharServer::GetClientByID( UINT charid )
{
for(UINT i=0;i<ClientList.size( );i++)
{
CCharClient* client = (CCharClient*) ClientList.at( i );
if(client->charid==charid)
{
return client;
}
}
return NULL;
}
// Search the client by char name
CCharClient* CCharServer::GetClientByName( char *name )
{
try
{
for(UINT i=0;i<ClientList.size( );i++)
{
CCharClient* client = (CCharClient*) ClientList.at( i );
if(strcmp(client->charname, name)==0)
{
return client;
}
}
}
catch(...)
{
return NULL;
}
return NULL;
}
// Search the client by char name
CCharClient* CCharServer::GetClientByUserName( char *username )
{
for(UINT i=0;i<ClientList.size( );i++)
{
CCharClient* client = (CCharClient*) ClientList.at( i );
if(strcmp(client->username, username)==0)
{
return client;
}
}
return NULL;
}
// Search the clan by clan id
CClans* CCharServer::GetClanByID( int id )
{
for(UINT i=0;i<ClanList.size();i++)
{
CClans* thisclan = ClanList.at( i );
if (thisclan->id==id)
return thisclan;
}
return NULL;
}
// Send packet to all the clan members
bool CCharServer::SendToClanMembers( int clanid,CPacket* pak )
{
CClans* thisclan = GetClanByID(clanid);
if(thisclan==0)
return false;
for(UINT i=0;i<thisclan->ClanMembers.size();i++)
{
CClanMembers* thismember = thisclan->ClanMembers.at(i);
CCharClient* otherclient = (CCharClient*) GetClientByID (thismember->id);
if(otherclient!=0)
{
otherclient->SendPacketCpy(pak);
}
}
return true;
}
// Update clan window all members 07
bool CCharServer::UpdateClanWindow( int clanid )
{
CClans* thisclan = GetClanByID(clanid);
if(thisclan==0)
return false;
for(UINT i=0;i<thisclan->ClanMembers.size();i++)
{
CClanMembers* thismember = thisclan->ClanMembers.at(i);
CCharClient* otherclient = (CCharClient*) GetClientByID (thismember->id);
if(otherclient!=0)
{
BEGINPACKET( pak, 0x7e0);
ADDBYTE ( pak, 0x33);
ADDWORD ( pak, clanid);
ADDWORD ( pak, 0x0000);
ADDWORD ( pak, thisclan->back );//clan background
ADDWORD ( pak, thisclan->logo );//clanlogo
ADDBYTE ( pak, thisclan->grade);//clan grade
ADDBYTE ( pak, otherclient->clan_rank);
ADDDWORD ( pak, thisclan->cp );
ADDDWORD ( pak, 0x00000064 );
ADDDWORD ( pak, 0x00000000 );
ADDDWORD ( pak, 0x00000000 );
ADDWORD ( pak, 0x0003 );//?????????
ADDWORD ( pak, 0x0000 );
ADDWORD ( pak, 0x0000 );
for(int i=0;i<119;i++)
ADDBYTE ( pak, 0x00);
ADDSTRING ( pak, thisclan->name);//clan name
ADDBYTE ( pak, 0x00);
ADDSTRING ( pak, thisclan->slogan);//Clan slogan
ADDBYTE ( pak, 0x00);
ADDSTRING ( pak, thisclan->news);//Clan news
ADDBYTE ( pak, 0x00);
otherclient->SendPacket(&pak);
}
}
return true;
}
// Get channel by id
CChanels* CCharServer::GetChannelByID( unsigned int id )
{
for(unsigned int i=0;i<ChannelList.size();i++)
{
CChanels* thischannel = ChannelList.at(i);
if(thischannel->id==id)
return thischannel;
}
return NULL;
}
// Returns the current time/date
unsigned long int CCharServer::GetServerTime( )
{
// Get time/date and write it to the beginning of the row
time_t rawtime; // For time
struct tm* timeinfo; // "
time ( &rawtime );
timeinfo = localtime( &rawtime );
unsigned long int uCurTime = 0;
uCurTime += (timeinfo->tm_sec * 1 );
uCurTime += (timeinfo->tm_min * 60 );
uCurTime += (timeinfo->tm_hour * 3600 );
uCurTime += (timeinfo->tm_yday * 86400 );
uCurTime += ((timeinfo->tm_year-2000) * 86400*366 );
return uCurTime;
}
+67
View File
@@ -0,0 +1,67 @@
/*
Rose Online Server Emulator
Copyright (C) 2006,2007 OSRose Team http://osroseon.to.md
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
depeloped with Main erose/hrose source server + some change from the original eich source
*/
#include "charserver.h"
unsigned char LOG_THISSERVER = 0;
class CCharServer* GServer;
// Main function
int main(int argc, char *argv[])
{
LOG_THISSERVER = LOG_CHARACTER_SERVER;
InitWinSocket( );
string fileconf = "charserver.conf";
if(argc>1)
{
fileconf = argv[1];
}
CCharServer *server = new (nothrow) CCharServer( fileconf );
if(server==NULL)
return -1;
MYSQL mysql;
server->DB = new CDatabase( server->Config.SQLServer.pcServer,
server->Config.SQLServer.pcUserName,
server->Config.SQLServer.pcPassword,
server->Config.SQLServer.pcDatabase,
server->Config.SQLServer.pcPort, &mysql );
server->port = server->Config.CharPort;
if(server->Config.usethreads)
Log( MSG_INFO, "Using Threads" );
if(server->DB->Connect( )==0) Log( MSG_INFO, "Connected to MySQL server" );
else
{
delete server;
#ifdef _WIN32
system("pause");
#endif
return -1;
}
server->LoadEncryption ();
// Start server
server->StartServer();
// Close server
server->DB->Disconnect( );
delete server;
CloseWinSocket( );
return EXIT_SUCCESS;
}
// -----------------------------------------------------------------------------------------
+109
View File
@@ -0,0 +1,109 @@
/*
Rose Online Server Emulator
Copyright (C) 2006,2007 OSRose Team http://osroseon.to.md
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
depeloped with Main erose/hrose source server + some change from the original eich source
*/
#include "charserver.h"
/*
/ from signal.h
* NOTE: SIGINT is produced when the user presses Ctrl-C.
* SIGILL has not been tested.
* SIGFPE doesn't seem to work?
* SIGSEGV does not catch writing to a NULL pointer (that shuts down
* your app; can you say "segmentation violation core dump"?).
* SIGTERM comes from what kind of termination request exactly?
* SIGBREAK is indeed produced by pressing Ctrl-Break.
* SIGABRT is produced by calling abort.
*/
void StartSignal( )
{
signal( SIGINT, HandleSignal );
signal( SIGILL, HandleSignal );
signal( SIGFPE, HandleSignal );
signal( SIGSEGV, HandleSignal );
signal( SIGTERM, HandleSignal );
signal( SIGBREAK, HandleSignal );
signal( SIGABRT, HandleSignal );
}
void StopSignal( )
{
signal( SIGINT, 0 );
signal( SIGILL, 0 );
signal( SIGFPE, 0 );
signal( SIGSEGV, 0 );
signal( SIGTERM, 0 );
signal( SIGBREAK, 0 );
signal( SIGABRT, 0 );
}
void HandleSignal( int num )
{
switch(num)
{
case SIGINT:/* Interactive attention */
Log( MSG_ERROR, "Signal received: SIGINT" );
#ifdef _WIN32
Sleep(1000);
#else
usleep(1000);
#endif
raise(num);
break;
case SIGILL:/* Illegal instruction */
Log( MSG_ERROR, "Signal received: SIGILL, Server will be closed, Trying to save..." );
GServer->isActive = false;
#ifdef _WIN32
Sleep(1000);
#else
usleep(1000);
#endif
raise(num);
break;
case SIGFPE:/* Floating point error */
Log( MSG_ERROR, "Signal received: SIGFPE, Server will be closed, Trying to save..." );
GServer->isActive = false;
raise(num);
break;
case SIGSEGV:/* Segmentation violation */
Log( MSG_ERROR, "Signal received: SIGSEGV, Server will be closed, Trying to save..." );
GServer->isActive = false;
#ifdef _WIN32
Sleep(1000);
#else
usleep(1000);
#endif
raise(num);
break;
case SIGTERM:/* Termination request */
Log( MSG_INFO, "Signal received: SIGTERM, Server will be closed" );
GServer->isActive = false;
break;
#ifdef _WIN32
case SIGBREAK:/* Control-break */
Log( MSG_INFO, "Signal received: SIGBREAK, Server will be closed" );
GServer->isActive = false;
break;
#endif
default:
cout << "Unknown Signal Number: " << num << endl;
raise(num);
}
}