Remove calls to Game_ParseClientCommand with per-gamemode overridable ClientCommand() method within NSGameRules.
Also redo the way chat messages are handled, so mods don't have to implement it themselves all the time.
This commit is contained in:
parent
da4501a90d
commit
1acbd8a34d
5 changed files with 78 additions and 15 deletions
|
@ -14,8 +14,6 @@
|
|||
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
void SV_SendChat(entity sender, string msg, entity eEnt, float fType);
|
||||
|
||||
botstate_t
|
||||
bot::GetState(void)
|
||||
{
|
||||
|
|
|
@ -17,16 +17,11 @@
|
|||
void
|
||||
bot::ChatSay(string msg)
|
||||
{
|
||||
SV_SendChat(this, msg, world, 0);
|
||||
g_grMode.ChatMessageAll(this, msg);
|
||||
}
|
||||
|
||||
void
|
||||
bot::ChatSayTeam(string msg)
|
||||
{
|
||||
entity a;
|
||||
for (a = world; (a = find(a, ::classname, "player"));) {
|
||||
if (a.team == this.team) {
|
||||
SV_SendChat(self, msg, a, 1);
|
||||
}
|
||||
}
|
||||
g_grMode.ChatMessageTeam(this, msg);
|
||||
}
|
||||
|
|
|
@ -35,8 +35,10 @@ public:
|
|||
/* logic */
|
||||
/** Overridable: Called every server frame. */
|
||||
virtual void FrameStart(void);
|
||||
/** Overridable: Called when a client issues a server command. */
|
||||
/** Overridable: Called when a client issues a console command. */
|
||||
virtual bool ConsoleCommand(NSClientPlayer,string);
|
||||
/** Overridable: Called when a client issues a client command. */
|
||||
virtual bool ClientCommand(NSClient,string);
|
||||
|
||||
/* client */
|
||||
/** Overridable: Called when a NSClientPlayer joins the server. */
|
||||
|
@ -90,6 +92,15 @@ public:
|
|||
virtual bool IsTeamplay(void);
|
||||
/** Returns if the gamerule is a multiplayer game. */
|
||||
virtual bool IsMultiplayer(void);
|
||||
|
||||
/* chat related methods */
|
||||
/** Called by Nuclide when the server has received a chat message
|
||||
that is to be distributed amongst all clients, regardless of team. */
|
||||
virtual void ChatMessageAll(NSClient, string);
|
||||
|
||||
/** Called by Nuclide when the server has received a chat message
|
||||
that is to be distributed amongst all clients of the same team. */
|
||||
virtual void ChatMessageTeam(NSClient, string);
|
||||
|
||||
/* spectator */
|
||||
/*
|
||||
|
|
|
@ -65,6 +65,11 @@ NSGameRules::ConsoleCommand(NSClientPlayer pl, string cmd)
|
|||
{
|
||||
return (false);
|
||||
}
|
||||
bool
|
||||
NSGameRules::ClientCommand(NSClient pl, string cmd)
|
||||
{
|
||||
return (false);
|
||||
}
|
||||
|
||||
/* client */
|
||||
void
|
||||
|
@ -463,3 +468,44 @@ NSGameRules::PlayerCanAttack(NSClientPlayer bp)
|
|||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
NSGameRules::ChatMessageAll(NSClient cl, string strMessage)
|
||||
{
|
||||
WriteByte(MSG_MULTICAST, SVC_CGAMEPACKET);
|
||||
WriteByte(MSG_MULTICAST, EV_CHAT);
|
||||
WriteByte(MSG_MULTICAST, num_for_edict(cl) - 1);
|
||||
WriteByte(MSG_MULTICAST, cl.team);
|
||||
WriteString(MSG_MULTICAST, strMessage);
|
||||
multicast([0,0,0], MULTICAST_ALL_R);
|
||||
|
||||
localcmd(sprintf("echo [ALL] %s: %s\n", cl.netname, strMessage));
|
||||
}
|
||||
|
||||
void
|
||||
NSGameRules::ChatMessageTeam(NSClient cl, string strMessage)
|
||||
{
|
||||
/* their finger probably slipped */
|
||||
if (IsTeamplay() == false) {
|
||||
ChatMessageAll(cl, strMessage);
|
||||
return;
|
||||
}
|
||||
|
||||
/* single handedly pick out team members */
|
||||
for (entity a = world; (a = find(a, ::classname, "player"));) {
|
||||
/* not one of us! */
|
||||
if (a.team != cl.team)
|
||||
continue;
|
||||
|
||||
WriteByte(MSG_MULTICAST, SVC_CGAMEPACKET);
|
||||
WriteByte(MSG_MULTICAST, EV_CHAT_TEAM);
|
||||
WriteByte(MSG_MULTICAST, num_for_edict(cl) - 1);
|
||||
WriteByte(MSG_MULTICAST, cl.team);
|
||||
WriteString(MSG_MULTICAST, strMessage);
|
||||
|
||||
msg_entity = a;
|
||||
multicast([0,0,0], MULTICAST_ONE_R);
|
||||
}
|
||||
|
||||
localcmd(sprintf("echo [TEAM] %s: %s\n", cl.netname, strMessage));
|
||||
}
|
||||
|
|
|
@ -280,15 +280,28 @@ void
|
|||
SV_ParseClientCommand(string cmd)
|
||||
{
|
||||
string newcmd = Plugin_ParseClientCommand(cmd);
|
||||
int argc;
|
||||
|
||||
if (newcmd == __NULL__)
|
||||
Game_ParseClientCommand(cmd);
|
||||
else
|
||||
Game_ParseClientCommand(newcmd);
|
||||
/* give the game-mode a chance to override us */
|
||||
if (g_ents_initialized)
|
||||
if (g_grMode.ClientCommand((NSClient)self, cmd) == true)
|
||||
return;
|
||||
|
||||
tokenize(cmd);
|
||||
argc = tokenize(cmd);
|
||||
|
||||
switch (argv(0)) {
|
||||
case "say":
|
||||
if (argc == 2)
|
||||
g_grMode.ChatMessageAll(self, argv(1));
|
||||
else
|
||||
g_grMode.ChatMessageAll(self, substring(cmd, 5, -2));
|
||||
break;
|
||||
case "say_team":
|
||||
if (argc == 2)
|
||||
g_grMode.ChatMessageTeam(self, argv(1));
|
||||
else
|
||||
g_grMode.ChatMessageTeam(self, substring(cmd, 10, -2));
|
||||
break;
|
||||
case "spectate":
|
||||
if (self.classname != "player")
|
||||
break;
|
||||
|
|
Loading…
Reference in a new issue