* more fixes to make gcc happy

* replaced DefScriptTools::toString() with more generic template functions
This commit is contained in:
false_genesis 2008-03-24 13:29:10 +00:00
parent 0c0771ee72
commit 12045179e4
10 changed files with 77 additions and 78 deletions

View File

@ -86,7 +86,7 @@ public:
~DefScript();
inline std::string GetLine(unsigned int id) { return Line[id]; }
inline unsigned int DefScript::GetLines(void) { return Line.size(); }
inline unsigned int GetLines(void) { return Line.size(); }
bool AddLine(std::string );
std::string GetName(void);
void SetName(std::string);
@ -256,24 +256,24 @@ private:
DefReturnResult func_bbsize(CmdSet&);
// file functions
DefReturnResult DefScriptPackage::func_fopen(CmdSet&);
DefReturnResult DefScriptPackage::func_fclose(CmdSet&);
DefReturnResult DefScriptPackage::func_fisopen(CmdSet&);
DefReturnResult DefScriptPackage::func_feof(CmdSet&);
DefReturnResult DefScriptPackage::func_frpos(CmdSet&);
DefReturnResult DefScriptPackage::func_fwpos(CmdSet&);
DefReturnResult DefScriptPackage::func_fdel(CmdSet&);
DefReturnResult DefScriptPackage::func_fflush(CmdSet&);
DefReturnResult DefScriptPackage::func_fwrite(CmdSet&);
DefReturnResult DefScriptPackage::func_fread(CmdSet&);
DefReturnResult DefScriptPackage::func_freadb(CmdSet&);
DefReturnResult DefScriptPackage::func_fwriteb(CmdSet&);
DefReturnResult DefScriptPackage::func_freadbb(CmdSet&);
DefReturnResult DefScriptPackage::func_fwritebb(CmdSet&);
DefReturnResult DefScriptPackage::func_fsize(CmdSet&);
DefReturnResult DefScriptPackage::func_freadline(CmdSet&);
DefReturnResult DefScriptPackage::func_fseekw(CmdSet&);
DefReturnResult DefScriptPackage::func_fseekr(CmdSet&);
DefReturnResult func_fopen(CmdSet&);
DefReturnResult func_fclose(CmdSet&);
DefReturnResult func_fisopen(CmdSet&);
DefReturnResult func_feof(CmdSet&);
DefReturnResult func_frpos(CmdSet&);
DefReturnResult func_fwpos(CmdSet&);
DefReturnResult func_fdel(CmdSet&);
DefReturnResult func_fflush(CmdSet&);
DefReturnResult func_fwrite(CmdSet&);
DefReturnResult func_fread(CmdSet&);
DefReturnResult func_freadb(CmdSet&);
DefReturnResult func_fwriteb(CmdSet&);
DefReturnResult func_freadbb(CmdSet&);
DefReturnResult func_fwritebb(CmdSet&);
DefReturnResult func_fsize(CmdSet&);
DefReturnResult func_freadline(CmdSet&);
DefReturnResult func_fseekw(CmdSet&);
DefReturnResult func_fseekr(CmdSet&);
// setup own function declarations here
# include "DefScriptInterfaceInclude.h"

View File

@ -23,27 +23,6 @@ std::string DefScriptTools::stringToUpper(std::string s)
return s;
}
std::string DefScriptTools::toString(ldbl num)
{
std::stringstream ss;
ss.setf(std::ios_base::fixed);
ss.precision(15);
ss << Round(num,15);
std::string s(ss.str());
while(s[s.length()-1]=='0')
s.erase(s.length()-1,1);
if(s[s.length()-1]=='.')
s.erase(s.length()-1,1);
return s;
}
std::string DefScriptTools::toString(uint64 num)
{
std::stringstream ss;
ss << num;
return ss.str();
}
// convert a string into ldbl
// valid input formats:
// normal numbers: 5439

View File

@ -1,17 +1,41 @@
#ifndef _DEFSCRIPTTOOLS_H
#define _DEFSCRIPTTOOLS_H
#include <sstream>
namespace DefScriptTools
{
std::string stringToUpper(std::string);
std::string stringToLower(std::string);
std::string toString(ldbl);
std::string toString(uint64);
ldbl toNumber(std::string);
bool isTrue(std::string);
uint64 toUint64(std::string);
uint64 atoi64(const char*);
inline long double Round(long double z,unsigned int n);
template <class T> inline std::string toString(T num)
{
std::stringstream ss;
ss << num;
return ss.str();
}
template <ldbl> inline std::string toString(ldbl num)
{
std::stringstream ss;
ss.setf(std::ios_base::fixed);
ss.precision(15);
ss << Round(num,15);
std::string s(ss.str());
while(s[s.length()-1]=='0')
s.erase(s.length()-1,1);
if(s[s.length()-1]=='.')
s.erase(s.length()-1,1);
return s;
}
template <float> inline std::string toString(float num)
{
return toString<ldbl>(num);
}
}

View File

@ -21,7 +21,7 @@ public:
void UnlinkByPtr(T*);
std::string GetNameByPtr(T*);
inline std::map<std::string,T*> &GetMap(void) { return _storage; }
inline bool SetKeepOnDestruct(bool b = true) { _keep = true; }
inline void SetKeepOnDestruct(bool b = true) { _keep = true; }
inline unsigned int Size(void) { return _storage.size(); }
void Clear(bool keep = false);

View File

@ -329,7 +329,7 @@ DefReturnResult DefScriptPackage::SCtarget(CmdSet& Set)
if(obj && (obj->IsUnit() || obj->IsCorpse())) // only units and corpses are targetable
{
ws->SendSetSelection(guid); // will also set the target for myCharacter
return toString(guid);
return DefScriptTools::toString(guid);
}
else
{
@ -366,7 +366,7 @@ DefReturnResult DefScriptPackage::SCloadscp(CmdSet& Set)
logerror("Failed to load SCP: \"%s\" [%s]",dbname.c_str(),Set.defaultarg.c_str());
}
}
return toString((uint64)sections);;
return DefScriptTools::toString((uint64)sections);;
}
DefReturnResult DefScriptPackage::SCScpExists(CmdSet& Set)
@ -443,7 +443,7 @@ DefReturnResult DefScriptPackage::SCGetPlayerGuid(CmdSet& Set)
else
{
uint64 guid=((PseuInstance*)parentMethod)->GetWSession()->plrNameCache.GetGuid(Set.defaultarg);
r.ret=toString(guid);
r.ret=DefScriptTools::toString(guid);
}
return r;
}
@ -1221,8 +1221,8 @@ void DefScriptPackage::My_Run(std::string line, std::string username)
{
CmdSet Set;
Set.arg[0] = username;
Set.arg[1] = toString(usrperm);
Set.arg[2] = toString(scperm);
Set.arg[1] = DefScriptTools::toString(usrperm);
Set.arg[2] = DefScriptTools::toString(scperm);
Set.arg[3] = curSet.cmd;
RunScript("_nopermission",&Set);
return;

View File

@ -85,7 +85,7 @@ public:
inline std::string GetConfDir(void) { return _confdir; }
inline void SetScpDir(std::string dir) { _scpdir = dir; }
inline void SetSessionKey(BigNumber key) { _sessionkey = key; }
inline BigNumber GetSessionKey(void) { return _sessionkey; }
inline BigNumber *GetSessionKey(void) { return &_sessionkey; }
inline void SetError(void) { _error = true; }
SCPDatabaseMgr dbmgr;

View File

@ -289,7 +289,7 @@ void RealmSession::_HandleRealmList(ByteBuffer& pkt)
GetInstance()->GetConf()->worldport=atoi(realmAddr.substr(colonpos+1,realmAddr.length()-colonpos-1).c_str());
// set vars
GetInstance()->GetScripts()->variables.Set("WORLDHOST",GetInstance()->GetConf()->worldhost);
GetInstance()->GetScripts()->variables.Set("WORLDPORT",toString((uint64)(GetInstance()->GetConf()->worldport)));
GetInstance()->GetScripts()->variables.Set("WORLDPORT",DefScriptTools::toString((uint64)(GetInstance()->GetConf()->worldport)));
// now we have the correct addr/port, time to create the WorldSession
GetInstance()->CreateWorldSession(); // will be done at next PseuInstance::Update()

View File

@ -142,7 +142,7 @@ void Channel::HandleNotifyOpcode(WorldPacket &packet)
name = _worldSession->GetOrRequestPlayerName(guid);
if (name.empty())
{
_worldSession->_DelayWorldPacket(packet,_worldSession->GetLagMS() * 1.2f);
_worldSession->_DelayWorldPacket(packet, uint32(_worldSession->GetLagMS() * 1.2f));
return;
}
}
@ -158,7 +158,7 @@ void Channel::HandleNotifyOpcode(WorldPacket &packet)
name = _worldSession->GetOrRequestPlayerName(guid);
if (name.empty())
{
_worldSession->_DelayWorldPacket(packet,_worldSession->GetLagMS() * 1.2f);
_worldSession->_DelayWorldPacket(packet, uint32(_worldSession->GetLagMS() * 1.2f));
return;
}
}
@ -232,7 +232,7 @@ void Channel::HandleListRequest(WorldPacket& recvPacket)
// all player names in this packet must be known before
if(_worldSession->GetOrRequestPlayerName(guid).empty())
{
_worldSession->_DelayWorldPacket(recvPacket, _worldSession->GetLagMS() * 1.2f);
_worldSession->_DelayWorldPacket(recvPacket, uint32(_worldSession->GetLagMS() * 1.2f));
must_delay = true;
}
cpl[guid] = mode;

View File

@ -71,4 +71,3 @@ float World::GetPosZ(float x, float y)
logdebug("WORLD: GetPosZ() called, but no MapMgr exists (do you really use maps?)");
return 0;
}

View File

@ -409,7 +409,7 @@ void WorldSession::_HandleAuthChallengeOpcode(WorldPacket& recvPacket)
uint32 clientseed_uint32=clientseed.AsDword();
digest.UpdateData((uint8*)&clientseed_uint32,sizeof(uint32));
digest.UpdateData((uint8*)&serverseed,sizeof(uint32));
digest.UpdateBigNumbers(&(GetInstance()->GetSessionKey()),NULL);
digest.UpdateBigNumbers(GetInstance()->GetSessionKey(),NULL);
digest.Finalize();
WorldPacket auth;
auth<<(uint32)(GetInstance()->GetConf()->clientbuild)<<unk<<acc<<clientseed_uint32;
@ -424,7 +424,7 @@ void WorldSession::_HandleAuthChallengeOpcode(WorldPacket& recvPacket)
// note that if the sessionkey/auth is wrong or failed, the server sends the following packet UNENCRYPTED!
// so its not 100% correct to init the crypt here, but it should do the job if authing was correct
_socket->InitCrypt(GetInstance()->GetSessionKey().AsByteArray(), 40);
_socket->InitCrypt(GetInstance()->GetSessionKey()->AsByteArray(), 40);
}
@ -516,8 +516,8 @@ void WorldSession::_HandleCharEnumOpcode(WorldPacket& recvPacket)
charId = i;
char_found=true;
_myGUID=plr[i]._guid;
GetInstance()->GetScripts()->variables.Set("@myguid",toString(plr[i]._guid));
GetInstance()->GetScripts()->variables.Set("@myrace",toString(plr[i]._race));
GetInstance()->GetScripts()->variables.Set("@myguid",DefScriptTools::toString(plr[i]._guid));
GetInstance()->GetScripts()->variables.Set("@myrace",DefScriptTools::toString((uint64)plr[i]._race));
}
}
@ -614,12 +614,12 @@ void WorldSession::_HandleMessageChatOpcode(WorldPacket& recvPacket)
name = GetOrRequestPlayerName(source_guid);
if(name.empty())
{
_DelayWorldPacket(recvPacket, GetLagMS() * 1.2f); // guess time how long it will take until we got player name from the server
_DelayWorldPacket(recvPacket, uint32(GetLagMS() * 1.2f)); // guess time how long it will take until we got player name from the server
return; // handle later
}
}
GetInstance()->GetScripts()->variables.Set("@thismsg_name",name);
GetInstance()->GetScripts()->variables.Set("@thismsg",toString(target_guid));
GetInstance()->GetScripts()->variables.Set("@thismsg",DefScriptTools::toString(target_guid));
DEBUG(logdebug("Chat packet recieved, type=%u lang=%u src="I64FMT" dst="I64FMT" chn='%s' len=%u",
@ -696,15 +696,12 @@ void WorldSession::_HandleMessageChatOpcode(WorldPacket& recvPacket)
}
}
// temporaray implementation of custom script to handle recieved chat messages
// TODO: needs to be replaced later by script hooks
// TODO: also _onwhisper must be replaced by this!
if(!isCmd && GetInstance()->GetScripts()->GetScript("_onchatmessage"))
{
CmdSet Set;
Set.arg[0] = toString(type);
Set.arg[1] = toString(lang);
Set.arg[2] = toString(target_guid);
Set.arg[0] = DefScriptTools::toString(type);
Set.arg[1] = DefScriptTools::toString(lang);
Set.arg[2] = DefScriptTools::toString(target_guid);
Set.arg[3] = channel;
Set.defaultarg = GetInstance()->GetScripts()->SecureString(msg);
GetInstance()->GetScripts()->RunScript("_onchatmessage",&Set);
@ -713,7 +710,7 @@ void WorldSession::_HandleMessageChatOpcode(WorldPacket& recvPacket)
if(isCmd)
{
GetInstance()->GetScripts()->variables.Set("@thiscmd_name",name);
GetInstance()->GetScripts()->variables.Set("@thiscmd",toString(target_guid));
GetInstance()->GetScripts()->variables.Set("@thiscmd",DefScriptTools::toString(target_guid));
std::string lin=msg.substr(1,msg.length()-1);
try
{
@ -871,11 +868,11 @@ void WorldSession::_HandleTelePortAckOpcode(WorldPacket& recvPacket)
{
CmdSet Set;
Set.defaultarg = "false"; // teleported to other map = false
Set.arg[0] = toString(guid);
Set.arg[1] = toString(x);
Set.arg[2] = toString(y);
Set.arg[3] = toString(z);
Set.arg[4] = toString(o);
Set.arg[0] = DefScriptTools::toString(guid);
Set.arg[1] = DefScriptTools::toString(x);
Set.arg[2] = DefScriptTools::toString(y);
Set.arg[3] = DefScriptTools::toString(z);
Set.arg[4] = DefScriptTools::toString(o);
GetInstance()->GetScripts()->RunScriptIfExists("_onteleport");
}
}
@ -932,11 +929,11 @@ void WorldSession::_HandleNewWorldOpcode(WorldPacket& recvPacket)
{
CmdSet Set;
Set.defaultarg = "true"; // teleported to other map = false
Set.arg[0] = toString(mapid);
Set.arg[1] = toString(x);
Set.arg[2] = toString(y);
Set.arg[3] = toString(z);
Set.arg[4] = toString(o);
Set.arg[0] = DefScriptTools::toString(mapid);
Set.arg[1] = DefScriptTools::toString(x);
Set.arg[2] = DefScriptTools::toString(y);
Set.arg[3] = DefScriptTools::toString(z);
Set.arg[4] = DefScriptTools::toString(o);
GetInstance()->GetScripts()->RunScriptIfExists("_onteleport");
}
}
@ -1033,7 +1030,7 @@ void WorldSession::_HandleEmoteOpcode(WorldPacket& recvPacket)
name = GetOrRequestPlayerName(guid);
if(name.empty())
{
_DelayWorldPacket(recvPacket, GetLagMS() * 1.2f);
_DelayWorldPacket(recvPacket, uint32(GetLagMS() * 1.2f));
return;
}
}