Scripts/Commands: Allow c++ style comments in opcode.txt file for .debug send opcode command.

This commit is contained in:
QAston
2011-09-01 10:46:15 +02:00
parent 71b9e0d8de
commit 68037cdc3c

View File

@@ -261,15 +261,58 @@ public:
if (ifs.bad())
return false;
// remove comments from file
std::stringstream parsedStream;
while (!ifs.eof())
{
char commentToken[2];
ifs.get(commentToken[0]);
if (commentToken[0] == '/' && !ifs.eof())
{
ifs.get(commentToken[1]);
// /* comment
if (commentToken[1] == '*')
{
while (!ifs.eof())
{
ifs.get(commentToken[0]);
if (commentToken[0] == '*' && !ifs.eof())
{
ifs.get(commentToken[1]);
if (commentToken[1] == '/')
break;
else
ifs.putback(commentToken[1]);
}
}
continue;
}
// line comment
else if (commentToken[1] == '/')
{
std::string str;
getline(ifs,str);
continue;
}
// regular data
else
{
ifs.putback(commentToken[1]);
}
}
parsedStream.put(commentToken[0]);
}
ifs.close();
uint32 opcode;
ifs >> opcode;
parsedStream >> opcode;
WorldPacket data(opcode, 0);
while (!ifs.eof())
while (!parsedStream.eof())
{
std::string type;
ifs >> type;
parsedStream >> type;
if (type == "")
break;
@@ -277,37 +320,37 @@ public:
if (type == "uint8")
{
uint16 val1;
ifs >> val1;
parsedStream >> val1;
data << uint8(val1);
}
else if (type == "uint16")
{
uint16 val2;
ifs >> val2;
parsedStream >> val2;
data << val2;
}
else if (type == "uint32")
{
uint32 val3;
ifs >> val3;
parsedStream >> val3;
data << val3;
}
else if (type == "uint64")
{
uint64 val4;
ifs >> val4;
parsedStream >> val4;
data << val4;
}
else if (type == "float")
{
float val5;
ifs >> val5;
parsedStream >> val5;
data << val5;
}
else if (type == "string")
{
std::string val6;
ifs >> val6;
parsedStream >> val6;
data << val6;
}
else if (type == "appitsguid")
@@ -350,7 +393,7 @@ public:
{
data << uint64(unit->GetGUID());
}
else if (type == "pos")
else if (type == "itspos")
{
data << unit->GetPositionX();
data << unit->GetPositionY();
@@ -368,7 +411,6 @@ public:
break;
}
}
ifs.close();
sLog->outDebug(LOG_FILTER_NETWORKIO, "Sending opcode %u", data.GetOpcode());
data.hexlike();
player->GetSession()->SendPacket(&data);