Initial MSVC 2008 projects workspace

This commit is contained in:
alexey.min
2012-02-01 05:25:08 +00:00
commit 03de3bdc95
1446 changed files with 476853 additions and 0 deletions

View File

@@ -0,0 +1,33 @@
#include "pch.h"
#include "Log.h"
#include "l2c_utils.h"
#include "net/GameClient/GameClient.h"
#include "../ClientPacketHandler.h"
#include "../ServerPackets.h"
#include "GS.h"
/* _loginName = readS().toLowerCase();
_playKey2 = readD();
_playKey1 = readD();
_loginKey1 = readD();
_loginKey2 = readD(); */
L2GamePacket *ClientPacketHandler::AuthLogin( L2GamePacket *pack )
{
GameServer *gs = GameServer::getInstance();
pack->getPacketType();
wchar_t login[128] = {0};
unsigned char loginKey[8] = {0,0,0,0,0,0,0,0};
unsigned char playKey[8] = {0,0,0,0,0,0,0,0};
wcsncpy( login, pack->readUnicodeStringPtr(), 128 ); login[127] = 0;
pack->readBytes( playKey+4, 4 );
pack->readBytes( playKey, 4 );
pack->readBytes( loginKey, 8 );
//
m_cl->setAccount( login );
m_cl->setSessionKeys( playKey, loginKey );
//
if( gs->getConfig()->Debug ) LogDebug( L"%s: AuthLogin %s", m_cl->toString(), login );
gs->addWaitingClientAndSendPlayerAuthRequest( login, loginKey, playKey );
return NULL;
}

View File

@@ -0,0 +1,213 @@
#include "pch.h"
#include "Log.h"
#include "l2c_utils.h"
#include "net/GameClient/GameClient.h"
#include "../ClientPacketHandler.h"
#include "../ServerPackets.h"
#include "GS.h"
#include "utils/Utils.h"
#include "datatables/CharNameTable.h"
#include "datatables/CharTemplateTable.h"
#include "datatables/ItemTable.h"
L2GamePacket *ClientPacketHandler::CharacterCreate( L2GamePacket *pack )
{
pack->getPacketType();
const wchar_t *name = pack->readUnicodeStringPtr(); // _name = readS();
int race = pack->readD(); // _race = readD();
int sex = pack->readD(); // _sex = readD();
int classId = pack->readD(); // _classId = readD();
pack->readD(); //_int = readD();
pack->readD(); //_str = readD();
pack->readD(); //_con = readD();
pack->readD(); //_men = readD();
pack->readD(); //_dex = readD();
pack->readD(); //_wit = readD();
int hairStyle = pack->readD(); //_hairStyle = readD();
int hairColor = pack->readD(); //_hairColor = readD();
int face = pack->readD(); //_face = readD();
// CharacterCreate
GameServer *gs = GameServer::getInstance();
int name_len = wcslen( name );
if( name_len < 1 || name_len > 16 )
{
if( gs->getConfig()->Debug )
LogWarning( L"%s: Character Creation Failure: Character name [%s] is invalid. "
L"Message generated: Your title cannot exceed 16 characters in length. Please try again.",
m_cl->toString(), name );
return ServerPackets::CharCreateFail( m_cl, L2Game_CharCreateFail::REASON_16_ENG_CHARS );
}
// alphanumeric name
if( !Utils_isValidCharName( name ) )
{
if( gs->getConfig()->Debug )
LogWarning( L"%s: Character Creation Failure: Character name [%s] is invalid. "
L"Message generated: Incorrect name. Please try again.", m_cl->toString(), name );
return ServerPackets::CharCreateFail( m_cl, L2Game_CharCreateFail::REASON_INCORRECT_NAME );
}
bool create_ok = false;
CharNameTable::getInstance()->LockDB();
if( !CharNameTable::getInstance()->doesCharNameExist( name ) )
{
// check maximum char count
int current_char_count = CharNameTable::getInstance()->getAccountCharCount( m_cl->getAccount() );
// TODO: CharacterCreate maximum char count may be in GS config?
if( current_char_count >= 7 )
{
if( gs->getConfig()->Debug ) LogWarning( L"%s: Max number of characters reached. Creation failed.", m_cl->toString() );
CharNameTable::getInstance()->UnlockDB();
return ServerPackets::CharCreateFail( m_cl, L2Game_CharCreateFail::REASON_TOO_MANY_CHARACTERS );
}
// get class template
const L2PlayerTemplate *tmpl = CharTemplateTable::getTemplate( classId );
if( !tmpl )
{
LogError( L"%s: CharacterCreate: template is NULL!", m_cl->toString() );
CharNameTable::getInstance()->UnlockDB();
return ServerPackets::CharCreateFail( m_cl, L2Game_CharCreateFail::REASON_CREATION_FAILED );
}
// base class must be 1 lvl
if( tmpl->classBaseLevel > 1 )
{
LogError( L"%s: CharacterCreate: template base level must be 1, but: %d!",
m_cl->toString(), tmpl->classBaseLevel );
CharNameTable::getInstance()->UnlockDB();
return ServerPackets::CharCreateFail( m_cl, L2Game_CharCreateFail::REASON_CREATION_FAILED );
}
// generate new objectId for char
unsigned int oid = gs->getIdFactory()->getNextObjectId();
// get race by class id
const ClassId *class_id = ClassIdTree::getInstance()->getClassId( classId );
assert( class_id != NULL );
int race_real = (int)class_id->getRace();
if( race_real != race )
LogWarning( L"%s: possible hacker: invalid race in CharacterCreate (%d)!=(%d)",
m_cl->toString(), race, race_real );
// insert new character into DB
MysqlQuery q;
q.create(
L"INSERT INTO characters ("
L"account_name,charId,char_name,level,maxHp,curHp,maxCp,curCp,maxMp,curMp,"
L"x,y,z,heading,"
L"face,hairStyle,hairColor,sex,exp,sp,karma,fame,pvpkills,pkkills,clanid,race,classid,"
L"deletetime,cancraft,title,accesslevel,online,isin7sdungeon,clan_privs,wantspeace,base_class,"
L"newbie,nobless,power_grade,last_recom_date) values ("
L"'%s',%u,'%s',1, %d,%d,%d,%d,%d,%d, " // acc,oid,charName, ...
L"%d,%d,%d,0, " // x,y,z,heading
L"%d,%d,%d, %d,0,0,0,0,0,0,0,%d,%d, " // face,hs,hc, ..
L"0,0,'',0,0,0,0,0,%d, " // deltime, ...
L"1,0,0,%u)", /////////////////////////////////////////////////////////////////////////
m_cl->getAccount(), oid, name, (int)(tmpl->baseHpMax), (int)(tmpl->baseHpMax),
(int)(tmpl->baseCpMax), (int)(tmpl->baseCpMax), (int)(tmpl->baseMpMax), (int)(tmpl->baseMpMax),
tmpl->spawnX, tmpl->spawnY, tmpl->spawnZ,
face, hairStyle, hairColor, sex, race_real, classId, classId, (unsigned int)time( NULL )
);
MysqlConnection *con = gs->getDBConnection();
if( con->executeQuery( q ) )
{
create_ok = true;
}
else
{
LogError( L"%s: CharacterCreate: cannot create: MySQL error: %s\n", m_cl->toString(), con->getErrorStr() );
}
q.clear();
// add shortcuts
//(int slotId, int pageId, int shortcutType, int shortcutId, int shortcutLevel, int characterType)
// add attack shortcut L2ShortCut(0, 0, 3, 2, 0, 1);
q.create( L"INSERT INTO character_shortcuts (charId,slot,page,type,shortcut_id,level,class_index) VALUES ('%u',0,0,3,2,0,1)", oid );
if( !con->executeQuery( q ) ) LogError( L"CharacterCreate: shortcuts: MySQL: %s", con->getErrorStr() );
// add take shortcut L2ShortCut(3, 0, 3, 5, 0, 1);
q.create( L"INSERT INTO character_shortcuts (charId,slot,page,type,shortcut_id,level,class_index) VALUES ('%u',3,0,3,5,0,1)", oid );
if( !con->executeQuery( q ) ) LogError( L"CharacterCreate: shortcuts: MySQL: %s", con->getErrorStr() );
// add sit shortcut L2ShortCut(10, 0, 3, 0, 0, 1);
q.create( L"INSERT INTO character_shortcuts (charId,slot,page,type,shortcut_id,level,class_index) VALUES ('%u',10,0,3,0,0,1)", oid );
if( !con->executeQuery( q ) ) LogError( L"CharacterCreate: shortcuts: MySQL: %s", con->getErrorStr() );
// add start items
const std::list<L2PlayerTemplate::PcTemplateItem> itemsList = tmpl->getItems();
std::list<L2PlayerTemplate::PcTemplateItem>::const_iterator itemsListIter = itemsList.begin();
while( itemsListIter != itemsList.end() )
{
L2PlayerTemplate::PcTemplateItem item = (*itemsListIter);
const L2ItemTemplate *item_tmpl = ItemTable::getInstance()->getTemplate( item.getItemId() );
if( !item_tmpl )
{
LogError( L"CharacterCreate: cannot add starter item: template NULL (%d)", item.getItemId() );
continue;
}
//
q.clear();
unsigned int item_oid = gs->getIdFactory()->getNextObjectId();
if( item.isEquipped() )
{
// location set to paperdoll
q.create( L"INSERT INTO items (owner_id,item_id,count,loc,loc_data,enchant_level,"
L"object_id,custom_type1,custom_type2,mana_left,time) VALUES "
L"('%u','%d','%d','PAPERDOLL','%d',0,'%u','%d','%d','%d','%d')",
oid, item.getItemId(), item.getAmount(), (int)item_tmpl->getBodyPart(),
item_oid, item_tmpl->getType1(), item_tmpl->getType2(),
item_tmpl->getDuration(), item_tmpl->getTime() );
}
else
{
// location set to inventory
q.create( L"INSERT INTO items (owner_id,item_id,count,loc,loc_data,enchant_level,"
L"object_id,custom_type1,custom_type2,mana_left,time) VALUES "
L"('%u','%d','%d','INVENTORY','%d',0,'%u','%d','%d','%d','%d')",
oid, item.getItemId(), item.getAmount(), (int)item_tmpl->getBodyPart(),
item_oid, item_tmpl->getType1(), item_tmpl->getType2(),
item_tmpl->getDuration(), item_tmpl->getTime() );
}
if( !con->executeQuery( q ) )
LogError( L"CharacterCreate: cannot add starter item: MySQL error: %s", con->getErrorStr() );
// add tutbook shortcut
if( item.getItemId() == 5588 ) // CharacterCreate add Tutorial Guide...
{
// L2ShortCut(11, 0, 1, item.getObjectId(), 0, 1);
q.create( L"INSERT INTO character_shortcuts (charId,slot,page,type,shortcut_id,level,class_index) "
L"VALUES ('%u',11,0,1,'%u',0,1)", oid, item_oid );
if( !con->executeQuery( q ) )
LogError( L"CharacterCreate add Tutorial Guide: MySQL: %s", con->getErrorStr() );
}
//
itemsListIter++;
}
q.clear();
// TODO: CharacterCreate add starting skills (need SkillTable & SkillLearn)
gs->releaseDBConnection( con );
}
else
{
if( gs->getConfig()->Debug )
LogWarning( L"%s: Character Creation Failure: REASON_NAME_ALREADY_EXISTS.", m_cl->toString() );
CharNameTable::getInstance()->UnlockDB();
return ServerPackets::CharCreateFail( m_cl, L2Game_CharCreateFail::REASON_NAME_ALREADY_EXISTS );
}
CharNameTable::getInstance()->UnlockDB();
if( !create_ok )
{
return NULL;
}
return ServerPackets::CharCreateOK( m_cl );
}
/*
private static final String INSERT_CHARACTER = "INSERT INTO characters (account_name,charId,char_name,level,maxHp,curHp,maxCp,curCp,maxMp,curMp,face,hairStyle,hairColor,sex,exp,sp,karma,fame,pvpkills,pkkills,clanid,race,classid,deletetime,cancraft,title,accesslevel,online,isin7sdungeon,clan_privs,wantspeace,base_class,newbie,nobless,power_grade,last_recom_date) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
private static final String UPDATE_CHARACTER = "UPDATE characters SET level=?,maxHp=?,curHp=?,maxCp=?,curCp=?,maxMp=?,curMp=?,face=?,hairStyle=?,hairColor=?,sex=?,heading=?,x=?,y=?,z=?,exp=?,expBeforeDeath=?,sp=?,karma=?,fame=?,pvpkills=?,pkkills=?,rec_have=?,rec_left=?,clanid=?,race=?,classid=?,deletetime=?,title=?,accesslevel=?,online=?,isin7sdungeon=?,clan_privs=?,wantspeace=?,base_class=?,onlinetime=?,punish_level=?,punish_timer=?,newbie=?,nobless=?,power_grade=?,subpledge=?,last_recom_date=?,lvl_joined_academy=?,apprentice=?,sponsor=?,varka_ketra_ally=?,clan_join_expiry_time=?,clan_create_expiry_time=?,char_name=?,death_penalty_level=?,bookmarkslot=?,vitality_points=? WHERE charId=?";
private static final String RESTORE_CHARACTER = "SELECT account_name, charId, char_name, level, maxHp, curHp, maxCp, curCp, maxMp, curMp, face, hairStyle, hairColor, sex, heading, x, y, z, exp, expBeforeDeath, sp, karma, fame, pvpkills, pkkills, clanid, race, classid, deletetime, cancraft, title, rec_have, rec_left, accesslevel, online, char_slot, lastAccess, clan_privs, wantspeace, base_class, onlinetime, isin7sdungeon, punish_level, punish_timer, newbie, nobless, power_grade, subpledge, last_recom_date, lvl_joined_academy, apprentice, sponsor, varka_ketra_ally,clan_join_expiry_time,clan_create_expiry_time,death_penalty_level,bookmarkslot,vitality_points FROM characters WHERE charId=?";
*/

View File

@@ -0,0 +1,44 @@
#include "pch.h"
#include "Log.h"
#include "l2c_utils.h"
#include "net/GameClient/GameClient.h"
#include "../ClientPacketHandler.h"
#include "../ServerPackets.h"
#include "GS.h"
L2GamePacket *ClientPacketHandler::CharacterSelect( L2GamePacket *pack )
{
L2GamePacket *ret = NULL;
pack->getPacketType();
int charSlot = pack->readD();
LogDebug( L"CharacterSelect: charSlot : %d", charSlot );
// create &load player for game client if not exists
if( m_cl->getPlayer() == NULL )
{
GamePlayer *pl = new GamePlayer( m_cl, 0 );
// TODO: CharacterSelect: load char from base
m_cl->setPlayer( pl, true, CLIENT_STATE_IN_GAME ); // sets state to IN_GAME
//
L2Game_CharSelected *p = new L2Game_CharSelected();
ret = p;
p->p_char_name[0] = 0;
p->p_opcodeObfuscatorSeed = rand();
p->p_title[0] = 0;
p->p_classId = 0;
p->p_level = 1;
unsigned char playKey[8];
m_cl->getPlayKey( playKey );
p->p_sessionId = playKey[0] | (playKey[1] << 8) | (playKey[2] << 16) | (playKey[3] << 24); // playOkID1
//
p->create( L2_VERSION_T23 );
//
m_cl->setOpcodeObfuscationSeed( p->p_opcodeObfuscatorSeed );
}
else
LogError( L"Net: %s: CharacterSelect: already has player attached to GameClient?? Bad Bad Error or Cheater!",
m_cl->toString() );
//
return ret;
}

View File

@@ -0,0 +1,27 @@
#include "pch.h"
#include "Log.h"
#include "l2c_utils.h"
#include "net/GameClient/GameClient.h"
#include "../ClientPacketHandler.h"
#include "../ServerPackets.h"
#include "GS.h"
L2GamePacket *ClientPacketHandler::Logout( L2GamePacket *pack )
{
pack->getPacketType();
L2GamePacket *ret = NULL;
switch( m_cl->getState() )
{
case CLIENT_STATE_OFFLINE:
case CLIENT_STATE_CONNECTED:
case CLIENT_STATE_AUTHED:
ret = NULL;
m_cl->signalThreadStop( true ); // we can just disconnect player now
break;
case CLIENT_STATE_IN_GAME:
// TODO: check if player can logout here and now
// answer with RestartResponse (LogoutOK) or (LogoutFailed)
break;
}
return ret;
}

View File

@@ -0,0 +1,13 @@
#include "pch.h"
#include "Log.h"
#include "l2c_utils.h"
#include "net/GameClient/GameClient.h"
#include "../ClientPacketHandler.h"
#include "../ServerPackets.h"
#include "GS.h"
L2GamePacket *ClientPacketHandler::NewCharacter( L2GamePacket *pack )
{
pack = NULL; // just trigger
return ServerPackets::NewCharacterSuccess( m_cl );
}

View File

@@ -0,0 +1,37 @@
#include "pch.h"
#include "Log.h"
#include "l2c_utils.h"
#include "net/GameClient/GameClient.h"
#include "../ClientPacketHandler.h"
#include "../ServerPackets.h"
#include "GS.h"
L2GamePacket *ClientPacketHandler::ProtocolVersion( L2GamePacket *pack )
{
GameServer *gs = GameServer::getInstance();
pack->getPacketType();
int pv = pack->readD();
// just server ping?
if( pv == -2 )
{
m_cl->setProtocolOk( false );
m_cl->signalThreadStop( true );
if( gs->getConfig()->Debug ) LogDebug( L"%s: received server ping from client (%d)", m_cl->toString(), pv );
return NULL;
}
// protocol version validation
if( gs->getConfig()->Debug ) LogDebug( L"%s: protocol version %d", m_cl->toString(), pv );
if( pv < gs->getConfig()->min_game_protocol_version ||
pv > gs->getConfig()->max_game_protocol_version )
{
m_cl->setProtocolOk( false );
m_cl->signalThreadStop( true );
LogWarning( L"%s: invalid protocol version %d (must be [%d..%d])",
m_cl->toString(), pv,
gs->getConfig()->min_game_protocol_version,
gs->getConfig()->max_game_protocol_version );
}
else m_cl->setProtocolOk( true );
// reply KeyPacket
return ServerPackets::KeyPacket( m_cl );
}

View File

@@ -0,0 +1,15 @@
#include "pch.h"
#include "Log.h"
#include "l2c_utils.h"
#include "net/GameClient/GameClient.h"
#include "../ClientPacketHandler.h"
#include "../ServerPackets.h"
#include "GS.h"
L2GamePacket *ClientPacketHandler::RequestGotoLobby( L2GamePacket *pack )
{
pack = NULL; // unused here
return ServerPackets::CharacterSelectionInfo( m_cl );
}