Xonotic
sv_minigames.qh File Reference
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define REGISTER_MINIGAME(name, nicename)
 

Functions

void ClientCommand_minigame (entity caller, int request, int argc, string command)
 
void end_minigame (entity minigame_session)
 
void end_minigames ()
 
string invite_minigame (entity inviter, entity player)
 Invite a player to join in a minigame. More...
 
entity join_minigame (entity player, string game_id)
 Join an existing minigame session. More...
 
bool minigame_CheckSend (entity this, entity client)
 
entity minigame_find_player (entity client)
 
bool minigame_SendEntity (entity this, entity to, int sf)
 
bool MinigameImpulse (entity this, int imp)
 
void part_minigame (entity player)
 
entity start_minigame (entity player, string minigame)
 Create a new minigame session. More...
 

Variables

entity active_minigame
 For players: Minigame being played. More...
 
bool autocvar_sv_minigames
 
bool autocvar_sv_minigames_observer
 
entity minigame_players
 For minigame sessions: list of players For minigame_player: client entity. More...
 
entity minigame_sessions
 

Macro Definition Documentation

◆ REGISTER_MINIGAME

#define REGISTER_MINIGAME (   name,
  nicename 
)
Value:
REGISTER(Minigames, MINIGAME_##name, m_id, new_pure(minigame_descriptor)); \
int name##_server_event(entity, string, ...); \
REGISTER_INIT(MINIGAME_##name) { \
this.netname = strzone(strtolower(#name)); \
this.message = nicename; \
this.minigame_event = name##_server_event; \
} \
REGISTER_INIT(MINIGAME_##name)
#define REGISTER(...)
Register a new entity with a registry.
Definition: registry.qh:87
entity() spawn
int m_id
Definition: effect.qh:19
#define new_pure(class)
purely logical entities (.origin doesn't work)
Definition: oo.qh:62

Definition at line 56 of file sv_minigames.qh.

Function Documentation

◆ ClientCommand_minigame()

void ClientCommand_minigame ( entity  caller,
int  request,
int  argc,
string  command 
)

Definition at line 307 of file sv_minigames.qc.

References active_minigame, argv(), argv_end_index, autocvar_sv_minigames, CMD_REQUEST_COMMAND, CS(), entity(), error(), FOREACH, GetIndexedEntity(), invite_minigame(), join_minigame(), minigame_find_player(), minigame_sessions, NULL, part_minigame(), sprint(), start_minigame(), strcat(), substring(), and tokenize_console.

308 {
309  if ( !autocvar_sv_minigames )
310  {
311  sprint(caller,"Minigames are not enabled!\n");
312  return;
313  }
314 
315  if (request == CMD_REQUEST_COMMAND )
316  {
317  string minig_cmd = argv(1);
318  if ( minig_cmd == "create" && argc > 2 )
319  {
320  entity minig = start_minigame(caller, argv(2));
321  if ( minig )
322  sprint(caller,"Created minigame session: ",minig.netname,"\n");
323  else
324  sprint(caller,"Cannot start minigame session!\n");
325  return;
326  }
327  else if ( minig_cmd == "join" && argc > 2 )
328  {
329  entity minig = join_minigame(caller, argv(2));
330  if ( minig )
331  sprint(caller,"Joined: ",minig.netname,"\n");
332  else
333  {
334  Send_Notification(NOTIF_ONE, caller, MSG_CENTER, CENTER_JOIN_PREVENT_MINIGAME);
335  sprint(caller,"Cannot join given minigame session!\n");
336  }
337  return;
338  }
339  else if ( minig_cmd == "list" )
340  {
341  FOREACH(Minigames, true, sprint(caller, it.netname, " (", it.message, ") ", "\n"));
342  return;
343  }
344  else if ( minig_cmd == "list-sessions" )
345  {
346  entity e;
347  for ( e = minigame_sessions; e != NULL; e = e.list_next )
348  sprint(caller,e.netname,"\n");
349  return;
350  }
351  else if ( minig_cmd == "end" || minig_cmd == "part" )
352  {
353  if ( CS(caller).active_minigame )
354  {
355  part_minigame(caller);
356  sprint(caller,"Left minigame session\n");
357  }
358  else
359  sprint(caller,"You aren't playing any minigame...\n");
360  return;
361  }
362  else if ( minig_cmd == "invite" && argc > 2 )
363  {
364  if ( CS(caller).active_minigame )
365  {
366  entity client = GetIndexedEntity(argc, 2);
367  string error = invite_minigame(caller,client);
368  if ( error == "" )
369  {
370  sprint(caller,"You have invited ",client.netname,
371  " to join your game of ", CS(caller).active_minigame.descriptor.message, "\n");
372  }
373  else
374  sprint(caller,"Could not invite: ", error, ".\n");
375  }
376  else
377  sprint(caller,"You aren't playing any minigame...\n");
378  return;
379  }
380  else if ( CS(caller).active_minigame )
381  {
382  entity e = minigame_find_player(caller);
383  string subcommand = substring(command,argv_end_index(0),-1);
384  int arg_c = tokenize_console(subcommand);
385  if ( CS(caller).active_minigame.minigame_event(CS(caller).active_minigame,"cmd",e,arg_c,subcommand) )
386  return;
387 
388  }
389  else sprint(caller,strcat("Wrong command:^1 ",command,"\n"));
390  }
391 
392  sprint(caller, "\nUsage:^3 cmd minigame create <minigame>\n");
393  sprint(caller, " Start a new minigame session\n");
394  sprint(caller, "Usage:^3 cmd minigame join <session>\n");
395  sprint(caller, " Join an exising minigame session\n");
396  sprint(caller, "Usage:^3 cmd minigame list\n");
397  sprint(caller, " List available minigames\n");
398  sprint(caller, "Usage:^3 cmd minigame list-sessions\n");
399  sprint(caller, " List available minigames sessions\n");
400  sprint(caller, "Usage:^3 cmd minigame part|end\n");
401  sprint(caller, " Leave the current minigame\n");
402  sprint(caller, "Usage:^3 cmd minigame invite <player>\n");
403  sprint(caller, " Invite the given player to join you in a minigame\n");
404 }
entity GetIndexedEntity(int argc, float start_index)
Definition: common.qc:83
entity join_minigame(entity player, string game_id)
Join an existing minigame session.
entity() spawn
ClientState CS(Client this)
Definition: state.qh:47
void part_minigame(entity player)
#define argv_end_index
Definition: dpextensions.qh:30
entity active_minigame
Definition: cl_minigames.qh:85
spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 f1 s1 strcat(_("Level %s: "), "^BG%s\3\, _("^BGPress ^F2%s^BG to enter the game"))
#define NULL
Definition: post.qh:17
const int CMD_REQUEST_COMMAND
Definition: command.qh:3
bool autocvar_sv_minigames
Definition: sv_minigames.qh:3
#define tokenize_console
Definition: dpextensions.qh:24
string invite_minigame(entity inviter, entity player)
Invite a player to join in a minigame.
entity start_minigame(entity player, string minigame)
Create a new minigame session.
entity minigame_sessions
Definition: sv_minigames.qh:47
entity minigame_find_player(entity client)
#define FOREACH(list, cond, body)
Definition: iter.qh:19
+ Here is the call graph for this function:

◆ end_minigame()

void end_minigame ( entity  minigame_session)

Definition at line 224 of file sv_minigames.qc.

References entity(), etof(), findentity(), ftos(), GameLogEcho(), LOG_TRACE, minigame_sessions, NULL, owner, player_clear_minigame(), strcat(), and strfree.

Referenced by end_minigames(), minigame_rmplayer(), and start_minigame().

225 {
226  if ( minigame_session.owner )
227  minigame_session.owner.list_next = minigame_session.list_next;
228  else
229  minigame_sessions = minigame_session.list_next;
230 
231  minigame_session.minigame_event(minigame_session,"end");
232  GameLogEcho(strcat(":minigame:end:",minigame_session.netname));
233 
234 
235  entity e = NULL;
236  while( (e = findentity(e, owner, minigame_session)) )
237  if ( e.minigame_autoclean )
238  {
239  LOG_TRACE("SV Auto-cleaned: ",ftos(etof(e)), " (",e.classname,")");
240  delete(e);
241  }
242 
243  entity p;
244  for ( e = minigame_session.minigame_players; e != NULL; e = p )
245  {
246  p = e.list_next;
247  player_clear_minigame(e.minigame_players);
248  delete(e);
249  }
250 
251  strfree(minigame_session.netname);
252  delete(minigame_session);
253 }
entity() spawn
entity owner
Definition: main.qh:73
spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 f1 s1 strcat(_("Level %s: "), "^BG%s\3\, _("^BGPress ^F2%s^BG to enter the game"))
void player_clear_minigame(entity player)
Definition: sv_minigames.qc:6
#define NULL
Definition: post.qh:17
void GameLogEcho(string s)
Definition: gamelog.qc:12
#define LOG_TRACE(...)
Definition: log.qh:81
#define strfree(this)
Definition: string.qh:56
entity minigame_sessions
Definition: sv_minigames.qh:47
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ end_minigames()

void end_minigames ( )

Definition at line 255 of file sv_minigames.qc.

References end_minigame(), and minigame_sessions.

256 {
257  while ( minigame_sessions )
258  {
260  }
261 }
entity minigame_sessions
Definition: sv_minigames.qh:47
void end_minigame(entity minigame_session)
+ Here is the call graph for this function:

◆ invite_minigame()

string invite_minigame ( entity  inviter,
entity  player 
)

Invite a player to join in a minigame.

Returns
Error string

Definition at line 263 of file sv_minigames.qc.

References active_minigame, CS(), etof(), ftos(), GameLogEcho(), strcat(), and VerifyClientEntity().

Referenced by ClientCommand_minigame().

264 {
265  if ( !inviter || !CS(inviter).active_minigame )
266  return "Invalid minigame";
267  if ( VerifyClientEntity(player, true, false) <= 0 )
268  return "Invalid player";
269  if ( inviter == player )
270  return "You can't invite yourself";
271  if ( CS(player).active_minigame == CS(inviter).active_minigame )
272  return strcat(player.netname," is already playing");
273 
274  Send_Notification(NOTIF_ONE, player, MSG_INFO, INFO_MINIGAME_INVITE,
275  CS(inviter).active_minigame.netname, inviter.netname );
276 
277  GameLogEcho(strcat(":minigame:invite:",CS(inviter).active_minigame.netname,":",
278  ftos(etof(player)),":",player.netname));
279 
280  return "";
281 }
ClientState CS(Client this)
Definition: state.qh:47
float VerifyClientEntity(entity client, float must_be_real, float must_be_bots)
Definition: common.qc:47
entity active_minigame
Definition: cl_minigames.qh:85
spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 f1 s1 strcat(_("Level %s: "), "^BG%s\3\, _("^BGPress ^F2%s^BG to enter the game"))
void GameLogEcho(string s)
Definition: gamelog.qc:12
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ join_minigame()

entity join_minigame ( entity  player,
string  game_id 
)

Join an existing minigame session.

Returns
minigame session entity

Definition at line 200 of file sv_minigames.qc.

References autocvar_sv_minigames, entity(), IS_REAL_CLIENT, minigame_addplayer(), minigame_sessions, and NULL.

Referenced by ClientCommand_minigame().

201 {
202  if ( !autocvar_sv_minigames || !IS_REAL_CLIENT(player) )
203  return NULL;
204 
205  entity minig;
206  for ( minig = minigame_sessions; minig != NULL; minig = minig.list_next )
207  {
208  if ( minig.netname == game_id )
209  if ( minigame_addplayer(minig,player) )
210  return minig;
211  }
212 
213  return NULL;
214 }
entity() spawn
#define IS_REAL_CLIENT(v)
Definition: utils.qh:17
#define NULL
Definition: post.qh:17
bool autocvar_sv_minigames
Definition: sv_minigames.qh:3
int minigame_addplayer(entity minigame_session, entity player)
entity minigame_sessions
Definition: sv_minigames.qh:47
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ minigame_CheckSend()

bool minigame_CheckSend ( entity  this,
entity  client 
)

Definition at line 118 of file sv_minigames.qc.

References entity(), NULL, and owner.

Referenced by minigame_addplayer(), and msle_spawn().

119 {
120  entity e;
121  for ( e = this.owner.minigame_players; e != NULL; e = e.list_next )
122  if ( e.minigame_players == client )
123  return true;
124  return false;
125 }
entity() spawn
entity owner
Definition: main.qh:73
#define NULL
Definition: post.qh:17
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ minigame_find_player()

entity minigame_find_player ( entity  client)

Definition at line 283 of file sv_minigames.qc.

References active_minigame, CS(), entity(), and NULL.

Referenced by ClientCommand_minigame(), and MinigameImpulse().

284 {
285  if ( ! CS(client).active_minigame )
286  return NULL;
287  entity e;
288  for ( e = CS(client).active_minigame.minigame_players; e; e = e.list_next )
289  if ( e.minigame_players == client )
290  return e;
291  return NULL;
292 }
entity() spawn
ClientState CS(Client this)
Definition: state.qh:47
entity active_minigame
Definition: cl_minigames.qh:85
#define NULL
Definition: post.qh:17
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ minigame_SendEntity()

bool minigame_SendEntity ( entity  this,
entity  to,
int  sf 
)

Definition at line 64 of file sv_minigames.qc.

References classname, descriptor, entity(), etof(), MINIG_SF_CREATE, MINIG_SF_UPDATE, minigame_flags, minigame_players, MINIGAME_SIMPLELINKED_ENTITIES, msle_id(), netname, owner, team, WriteByte(), WriteLong(), WriteShort(), and WriteString().

Referenced by minigame_addplayer(), msle_spawn(), and start_minigame().

65 {
66  WriteHeader(MSG_ENTITY, ENT_CLIENT_MINIGAME);
67  WriteByte(MSG_ENTITY, sf);
68 
69  if ( sf & MINIG_SF_CREATE )
70  {
71  WriteShort(MSG_ENTITY,msle_id(this.classname));
72  WriteString(MSG_ENTITY,this.netname);
73  }
74 
75  entity minigame_ent = this.owner;
76 
77  if ( this.classname == "minigame" )
78  {
79  minigame_ent = this;
80 
81  if ( sf & MINIG_SF_CREATE )
82  WriteString(MSG_ENTITY,this.descriptor.netname);
83 
84  if ( sf & MINIG_SF_UPDATE )
85  WriteLong(MSG_ENTITY,this.minigame_flags);
86  }
87  else if ( this.classname == "minigame_player" )
88  {
89  if ( sf & MINIG_SF_CREATE )
90  {
91  WriteString(MSG_ENTITY,this.owner.netname);
92  WriteLong(MSG_ENTITY,etof(this.minigame_players));
93  }
94  if ( sf & MINIG_SF_UPDATE )
95  WriteByte(MSG_ENTITY,this.team);
96  }
98 
99  minigame_ent.minigame_event(minigame_ent,"network_send",this,sf);
100 
101  return true;
102 
103 }
int team
Definition: main.qh:157
entity() spawn
int msle_id(string class_name)
Definition: minigames.qc:99
string netname
Definition: powerups.qc:20
string classname
Definition: csprogsdefs.qc:107
int minigame_flags
Definition: minigames.qh:103
const int MINIG_SF_UPDATE
Definition: minigames.qh:109
entity owner
Definition: main.qh:73
#define MINIGAME_SIMPLELINKED_ENTITIES
How to create a minigame
Definition: all.qh:100
entity minigame_players
For minigame sessions: list of players For minigame_player: client entity.
Definition: sv_minigames.qh:45
const int MINIG_SF_CREATE
Definition: minigames.qh:108
entity descriptor
For minigame sessions: minigame descriptor object.
Definition: minigames.qh:45
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ MinigameImpulse()

bool MinigameImpulse ( entity  this,
int  imp 
)

Definition at line 294 of file sv_minigames.qc.

References active_minigame, CS(), entity(), and minigame_find_player().

Referenced by ImpulseCommands(), and ObserverOrSpectatorThink().

295 {
296  if (!CS(this).active_minigame) return false;
297  entity e = minigame_find_player(this);
298  if ( imp && CS(this).active_minigame && e )
299  {
300  return CS(this).active_minigame.minigame_event(CS(this).active_minigame,"impulse",e,imp);
301  }
302  return false;
303 }
int int int imp
Definition: impulse.qc:90
entity() spawn
ClientState CS(Client this)
Definition: state.qh:47
entity active_minigame
Definition: cl_minigames.qh:85
entity minigame_find_player(entity client)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ part_minigame()

void part_minigame ( entity  player)

Definition at line 216 of file sv_minigames.qc.

References CS(), entity(), and minigame_rmplayer().

Referenced by ClientCommand_minigame(), and ClientDisconnect().

217 {
218  entity minig = CS(player).active_minigame;
219 
220  if ( minig && minig.classname == "minigame" )
221  minigame_rmplayer(minig,player);
222 }
entity() spawn
ClientState CS(Client this)
Definition: state.qh:47
void minigame_rmplayer(entity minigame_session, entity player)
Definition: sv_minigames.qc:17
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ start_minigame()

entity start_minigame ( entity  player,
string  minigame 
)

Create a new minigame session.

Returns
minigame session entity

Definition at line 164 of file sv_minigames.qc.

References autocvar_sv_minigames, end_minigame(), entity(), etof(), ftos(), GameLogEcho(), IS_REAL_CLIENT, LOG_TRACE, minigame_addplayer(), minigame_get_descriptor(), minigame_SendEntity(), minigame_sessions, NULL, strcat(), and strzone().

Referenced by ClientCommand_minigame().

165 {
166  if ( !autocvar_sv_minigames || !IS_REAL_CLIENT(player) )
167  return NULL;
168 
169  entity e = minigame_get_descriptor(minigame);
170  if ( e )
171  {
172  entity minig = new(minigame);
173  minig.netname = strzone(strcat(e.netname,"_",ftos(etof(minig))));
174  minig.descriptor = e;
175  minig.minigame_event = e.minigame_event;
176  minig.minigame_event(minig,"start");
177  GameLogEcho(strcat(":minigame:start:",minig.netname));
178  if ( ! minigame_addplayer(minig,player) )
179  {
180  LOG_TRACE("Minigame ",minig.netname," rejected the first player join!");
181  end_minigame(minig);
182  return NULL;
183  }
184  Net_LinkEntity(minig, false, 0, minigame_SendEntity);
185 
186  if ( !minigame_sessions )
187  minigame_sessions = minig;
188  else
189  {
190  minigame_sessions.owner = minig;
191  minig.list_next = minigame_sessions;
192  minigame_sessions = minig;
193  }
194  return minig;
195  }
196 
197  return NULL;
198 }
entity() spawn
#define IS_REAL_CLIENT(v)
Definition: utils.qh:17
spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 f1 s1 strcat(_("Level %s: "), "^BG%s\3\, _("^BGPress ^F2%s^BG to enter the game"))
entity minigame_get_descriptor(string id)
Definition: minigames.qc:5
#define NULL
Definition: post.qh:17
bool autocvar_sv_minigames
Definition: sv_minigames.qh:3
void GameLogEcho(string s)
Definition: gamelog.qc:12
#define LOG_TRACE(...)
Definition: log.qh:81
int minigame_addplayer(entity minigame_session, entity player)
bool minigame_SendEntity(entity this, entity to, int sf)
Definition: sv_minigames.qc:64
entity minigame_sessions
Definition: sv_minigames.qh:47
void end_minigame(entity minigame_session)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ active_minigame

entity active_minigame

For players: Minigame being played.

Definition at line 41 of file sv_minigames.qh.

◆ autocvar_sv_minigames

bool autocvar_sv_minigames

Definition at line 3 of file sv_minigames.qh.

Referenced by ClientCommand_minigame(), join_minigame(), and start_minigame().

◆ autocvar_sv_minigames_observer

bool autocvar_sv_minigames_observer

Definition at line 4 of file sv_minigames.qh.

Referenced by minigame_addplayer().

◆ minigame_players

entity minigame_players

For minigame sessions: list of players For minigame_player: client entity.

Definition at line 45 of file sv_minigames.qh.

Referenced by minigame_SendEntity().

◆ minigame_sessions

entity minigame_sessions