Attached Files |
-
NETMSG_KILLALLUNITS.patch (4,175 bytes) 2007-11-20 04:25
Index: Game/Game.cpp
===================================================================
--- Game/Game.cpp (revision 4836)
+++ Game/Game.cpp (working copy)
@@ -3003,6 +3003,27 @@
break;
}
+ case NETMSG_KILLALLUNITS: {
+ const int player = inbuf[3];
+ if ((player < 0) || (player >= MAX_PLAYERS)) {
+ logOutput.Print("Got invalid player num %i in KillAllUnits message", player);
+ }
+ CUnitSet* tu = &gs->Team(player)->units;
+ for(CUnitSet::iterator ui = tu->begin(); ui != tu->end(); ++ui) {
+ if ((*ui) != NULL)
+ {
+ if ((*ui)->beingBuilt) {
+ (*ui)->KillUnit(false, true, NULL); // kill units under construction without explosion
+ }
+ else {
+ (*ui)->KillUnit(true, false, NULL);
+ }
+ }
+ }
+ AddTraffic(player, packetCode, dataLength);
+ break;
+ }
+
case NETMSG_SYNCREQUEST: {
// TODO rename this net message, change error msg, etc.
ENTER_MIXED;
Index: Game/GameServer.cpp
===================================================================
--- Game/GameServer.cpp (revision 4836)
+++ Game/GameServer.cpp (working copy)
@@ -525,7 +525,16 @@
serverNet->RawSend(inbuf,*((short int*)&inbuf[1])); //forward data
}
break;
-
+
+ case NETMSG_KILLALLUNITS:
+ if(inbuf[3]!=a){
+ SendSystemMsg("Server: Warning got KillAllUnits from %i claiming to be from %i",a,inbuf[3]);
+ }
+ else if(!play) {
+ serverNet->SendKillAllUnits(inbuf[1]); //forward data
+ }
+ break;
+
case NETMSG_SYNCRESPONSE:
#ifdef SYNCCHECK
if(inbuf[1]!=a){
Index: Game/UI/QuitBox.cpp
===================================================================
--- Game/UI/QuitBox.cpp (revision 4836)
+++ Game/UI/QuitBox.cpp (working copy)
@@ -255,8 +255,7 @@
}
// resign, so self-d all units
if(InBox(mx,my,box+resignQuitBox) || InBox(mx,my,box+resignBox)) {
- c.id=CMD_SELFD;
- selectedUnits.GiveCommand(c,false);
+ net->SendKillAllUnits(gu->myPlayerNum);
}
// (resign and) quit, so leave the game
if(InBox(mx,my,box+resignQuitBox)){
Index: System/BaseNetProtocol.cpp
===================================================================
--- System/BaseNetProtocol.cpp (revision 4836)
+++ System/BaseNetProtocol.cpp (working copy)
@@ -40,6 +40,7 @@
RegisterMessage(NETMSG_PLAYERLEFT, 3);
RegisterMessage(NETMSG_MODNAME, -1);
RegisterMessage(NETMSG_LUAMSG, -2);
+ RegisterMessage(NETMSG_KILLALLUNITS, 2);
}
CBaseNetProtocol::~CBaseNetProtocol()
@@ -313,7 +314,7 @@
return SendSTLData<uint, std::string> (NETMSG_MODNAME, checksum, newModName);
}
-// NETMSG_LUAMSG = 40, // uchar myPlayerNum; std::string modName; (e.g. `custom msg')
+// NETMSG_LUAMSG = 50, // uchar myPlayerNum; std::string modName; (e.g. `custom msg')
void CBaseNetProtocol::SendLuaMsg(uchar myPlayerNum, uchar script, uchar mode,
const std::string& msg)
@@ -329,9 +330,16 @@
data.push_back(script);
data.push_back(mode);
data.append(msg);
- return SendData((const unsigned char*)data.data(), msgLen);
+ return SendData((const unsigned char*)data.data(), msgLen);
}
+// NETMSG_KILLALLUNITS = 51 // uchar myPlayerNum;
+
+void CBaseNetProtocol::SendKillAllUnits(uchar myPlayerNum)
+{
+ return SendData<uchar>(NETMSG_KILLALLUNITS, myPlayerNum);
+}
+
/* FIXME: add these:
#ifdef SYNCDEBUG
@@ -343,4 +351,3 @@
#endif // SYNCDEBUG
*/
-
Index: System/BaseNetProtocol.h
===================================================================
--- System/BaseNetProtocol.h (revision 4836)
+++ System/BaseNetProtocol.h (working copy)
@@ -69,6 +69,7 @@
NETMSG_SD_RESET = 45,
#endif // SYNCDEBUG
NETMSG_LUAMSG = 50, // uchar myPlayerNum, std::string msg
+ NETMSG_KILLALLUNITS = 51,
};
/**
@@ -128,6 +129,7 @@
void SendPlayerLeft(uchar myPlayerNum, uchar bIntended);
void SendModName(const uint checksum, const std::string& modName);
void SendLuaMsg(uchar myPlayerNum, uchar script, uchar mode, const std::string& msg);
+ void SendKillAllUnits(uchar myPlayerNum);
private:
};
-
NETMSG_RESIGN.patch (4,192 bytes) 2007-11-21 05:59
Index: rts/Game/Game.cpp
===================================================================
--- rts/Game/Game.cpp (revision 4844)
+++ rts/Game/Game.cpp (working copy)
@@ -3003,6 +3003,27 @@
break;
}
+ case NETMSG_RESIGN: {
+ const int player = inbuf[3];
+ if ((player < 0) || (player >= MAX_PLAYERS)) {
+ logOutput.Print("Got invalid player num %i in Resign message", player);
+ }
+ CUnitSet* tu = &gs->Team(player)->units;
+ for(CUnitSet::iterator ui = tu->begin(); ui != tu->end(); ++ui) {
+ if ((*ui) != NULL)
+ {
+ if ((*ui)->beingBuilt) {
+ (*ui)->KillUnit(false, true, NULL); // kill units under construction without explosion
+ }
+ else {
+ (*ui)->KillUnit(true, false, NULL);
+ }
+ }
+ }
+ AddTraffic(player, packetCode, dataLength);
+ break;
+ }
+
case NETMSG_SYNCREQUEST: {
// TODO rename this net message, change error msg, etc.
ENTER_MIXED;
Index: rts/Game/GameServer.cpp
===================================================================
--- rts/Game/GameServer.cpp (revision 4844)
+++ rts/Game/GameServer.cpp (working copy)
@@ -525,7 +525,16 @@
serverNet->RawSend(inbuf,*((short int*)&inbuf[1])); //forward data
}
break;
-
+
+ case NETMSG_RESIGN:
+ if(inbuf[3]!=a){
+ SendSystemMsg("Server: Warning got Resign from %i claiming to be from %i",a,inbuf[3]);
+ }
+ else if(!play) {
+ serverNet->SendResign(inbuf[1]); //forward data
+ }
+ break;
+
case NETMSG_SYNCRESPONSE:
#ifdef SYNCCHECK
if(inbuf[1]!=a){
Index: rts/Game/UI/QuitBox.cpp
===================================================================
--- rts/Game/UI/QuitBox.cpp (revision 4844)
+++ rts/Game/UI/QuitBox.cpp (working copy)
@@ -255,8 +255,7 @@
}
// resign, so self-d all units
if(InBox(mx,my,box+resignQuitBox) || InBox(mx,my,box+resignBox)) {
- c.id=CMD_SELFD;
- selectedUnits.GiveCommand(c,false);
+ net->SendResign(gu->myPlayerNum);
}
// (resign and) quit, so leave the game
if(InBox(mx,my,box+resignQuitBox)){
Index: rts/System/BaseNetProtocol.cpp
===================================================================
--- rts/System/BaseNetProtocol.cpp (revision 4844)
+++ rts/System/BaseNetProtocol.cpp (working copy)
@@ -40,6 +40,7 @@
RegisterMessage(NETMSG_PLAYERLEFT, 3);
RegisterMessage(NETMSG_MODNAME, -1);
RegisterMessage(NETMSG_LUAMSG, -2);
+ RegisterMessage(NETMSG_RESIGN, 2);
}
CBaseNetProtocol::~CBaseNetProtocol()
@@ -313,7 +314,7 @@
return SendSTLData<uint, std::string> (NETMSG_MODNAME, checksum, newModName);
}
-// NETMSG_LUAMSG = 40, // uchar myPlayerNum; std::string modName; (e.g. `custom msg')
+// NETMSG_LUAMSG = 50, // uchar myPlayerNum; std::string modName; (e.g. `custom msg')
void CBaseNetProtocol::SendLuaMsg(uchar myPlayerNum, uchar script, uchar mode,
const std::string& msg)
@@ -329,9 +330,16 @@
data.push_back(script);
data.push_back(mode);
data.append(msg);
- return SendData((const unsigned char*)data.data(), msgLen);
+ return SendData((const unsigned char*)data.data(), msgLen);
}
+// NETMSG_RESIGN = 51 // uchar myPlayerNum;
+
+void CBaseNetProtocol::SendResign(uchar myPlayerNum)
+{
+ return SendData<uchar>(NETMSG_RESIGN, myPlayerNum);
+}
+
/* FIXME: add these:
#ifdef SYNCDEBUG
@@ -343,4 +351,3 @@
#endif // SYNCDEBUG
*/
-
Index: rts/System/BaseNetProtocol.h
===================================================================
--- rts/System/BaseNetProtocol.h (revision 4844)
+++ rts/System/BaseNetProtocol.h (working copy)
@@ -69,6 +69,7 @@
NETMSG_SD_RESET = 45,
#endif // SYNCDEBUG
NETMSG_LUAMSG = 50, // uchar myPlayerNum, std::string msg
+ NETMSG_RESIGN = 51,
};
/**
@@ -128,9 +129,11 @@
void SendPlayerLeft(uchar myPlayerNum, uchar bIntended);
void SendModName(const uint checksum, const std::string& modName);
void SendLuaMsg(uchar myPlayerNum, uchar script, uchar mode, const std::string& msg);
+ void SendResign(uchar myPlayerNum);
private:
};
#endif
+
|
---|