Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
net.qc File Reference
#include "net.qh"
#include <server/command/cmd.qh>
Include dependency graph for net.qc:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void GameTypeVote_ReadOption (int i)
void GameTypeVote_WriteOption (int i)
 Sends a single gametype vote option to the client.
void MapVote_Init_Client (int sf)
void MapVote_Init_Server ()
void MapVote_ReadMask ()
void MapVote_ReadOption (int i)
void MapVote_ReadPlayerVote (entity voter)
bool MapVote_SendEntity (entity this, entity to, int sf)
void MapVote_Spawn ()
void MapVote_TouchMask ()
void MapVote_Winner (int mappos)
void MapVote_WriteMask ()
void MapVote_WriteOption (int i)
 Sends a single map vote option to the client.
void MapVote_WritePicture (entity to, int id)
void MapVote_WritePlayerVote (int index)
 NET_HANDLE (ENT_CLIENT_MAPVOTE, bool isNew)
 NET_HANDLE (TE_CSQC_PICTURE, bool isNew)

Variables

entity mapvote_ent
float spamtime

Function Documentation

◆ GameTypeVote_ReadOption()

void GameTypeVote_ReadOption ( int i)

Definition at line 118 of file net.qc.

119{
120 TC(int, i);
122 mv_flags[i] = ReadByte();
123 mv_suggester[i] = "";
124
125 string basetype = "";
126
127 if (mv_flags[i] & GTV_CUSTOM)
128 {
129 string name = ReadString();
130 if (strlen(name) < 1)
131 name = mv_entries[i];
132 mv_data[i] = strzone(name);
133 mv_desc[i] = strzone(ReadString());
134 basetype = strzone(ReadString());
135 }
136 else
137 {
138 Gametype type = MapInfo_Type_FromString(mv_entries[i], false, false);
141 }
142
143 string mv_picpath = sprintf("gfx/menu/%s/gametype_%s", autocvar_menu_skin, mv_entries[i]);
144 if (precache_pic(mv_picpath) == "")
145 {
146 mv_picpath = strcat("gfx/menu/wickedx/gametype_", mv_entries[i]);
147 if (precache_pic(mv_picpath) == "")
148 {
149 mv_picpath = sprintf("gfx/menu/%s/gametype_%s", autocvar_menu_skin, basetype);
150 if (precache_pic(mv_picpath) == "")
151 mv_picpath = strcat("gfx/menu/wickedx/gametype_", basetype);
152 }
153 }
154 mv_pics[i] = strzone(mv_picpath);
156}
bool PreviewExists(string name)
string mv_desc[MAPVOTE_COUNT]
(gt) gametype description
string mv_data[MAPVOTE_COUNT]
(shared) map pk3 name/gametype human readable name
string autocvar_menu_skin
float mv_preview[MAPVOTE_COUNT]
(shared) whether there is a pic
string mv_pics[MAPVOTE_COUNT]
(shared) pic file location
#define ReadString
#define strlen
#define TC(T, sym)
Definition _all.inc:82
int ReadByte()
string MapInfo_Type_Description(Gametype t)
Definition mapinfo.qc:650
string MapInfo_Type_ToText(Gametype t)
Definition mapinfo.qc:660
Gametype MapInfo_Type_FromString(string gtype, bool dowarn, bool is_q3compat)
Definition mapinfo.qc:620
const int GTV_CUSTOM
Custom entry.
Definition mapvoting.qh:29
int mv_flags[MAPVOTE_COUNT]
(shared) map/gametype flags
Definition mapvoting.qh:18
string mv_entries[MAPVOTE_COUNT]
(shared) map name or gametype name
Definition mapvoting.qh:16
string mv_suggester[MAPVOTE_COUNT]
(maps) .netname of the player who suggested the map
Definition mapvoting.qh:17
string name
Definition menu.qh:30
string precache_pic(string name,...)
string strzone(string s)
strcat(_("^F4Countdown stopped!"), "\n^BG", _("Teams are too unbalanced."))

References autocvar_menu_skin, GTV_CUSTOM, MapInfo_Type_Description(), MapInfo_Type_FromString(), MapInfo_Type_ToText(), mv_data, mv_desc, mv_entries, mv_flags, mv_pics, mv_preview, mv_suggester, name, precache_pic(), PreviewExists(), ReadByte(), ReadString, strcat(), strlen, strzone(), and TC.

Referenced by MapVote_Init_Client().

◆ GameTypeVote_WriteOption()

void GameTypeVote_WriteOption ( int i)

Sends a single gametype vote option to the client.

Definition at line 105 of file net.qc.

106{
107 string type_name = mv_entries[i];
108 WriteString(MSG_ENTITY, type_name);
110 if (mv_flags[i] & GTV_CUSTOM)
111 {
112 WriteString(MSG_ENTITY, cvar_string(strcat("sv_vote_gametype_", type_name, "_name")));
113 WriteString(MSG_ENTITY, cvar_string(strcat("sv_vote_gametype_", type_name, "_description")));
114 WriteString(MSG_ENTITY, cvar_string(strcat("sv_vote_gametype_", type_name, "_type")));
115 }
116}
WriteString(chan, ent.netname)
WriteByte(chan, ent.angles.y/DEC_FACTOR)
const int MSG_ENTITY
Definition net.qh:156
const string cvar_string(string name)

References cvar_string(), GTV_CUSTOM, MSG_ENTITY, mv_entries, mv_flags, strcat(), WriteByte(), and WriteString().

Referenced by MapVote_Init_Server().

◆ MapVote_Init_Client()

void MapVote_Init_Client ( int sf)

Definition at line 194 of file net.qc.

195{
196 mv_active = true;
198 mousepos = (eX * vid_conwidth + eY * vid_conheight) * 0.5;
199 mv_selection = -1;
200 mv_selection_keyboard = false;
201
202 string s;
203 int i;
204 mv_ssdirs_count = ReadByte(); // will be < MAPVOTE_SSDIRS_COUNT
205 for (i = 0; i < mv_ssdirs_count; ++i)
206 mv_ssdirs[i] = ReadString();
207
208 mv_count_real = mv_count = ReadByte(); // will be < MAPVOTE_COUNT
209
211 if (mv_abstain)
213 mv_detail = (sf & SF_MV_DETAIL_WINNER) ? 2 : ((sf & SF_MV_DETAIL_COUNTS) ? 1 : 0);
214
217
218 mv_ownvote = -1;
220
221 int gametypevote_flags = ReadByte();
222 gametypevote = (gametypevote_flags == SF_MV_GTV_NOW);
223 if (gametypevote_flags != SF_MV_GTV_MAPS)
225
227 for (i = 0; i < mv_count; ++i)
228 mv_flags_start[i] = mv_flags[i];
229
230 // Assume mv_pk3list is NULL, there should only be 1 mapvote per round
231 mv_pk3list = NULL; // I'm still paranoid!
232
234 for (i = 0; i < mv_count_real; ++i)
235 {
236 mv_votes[i] = 0;
237 mv_select_lasttime[i] = 0;
238 ReadOption(i);
239 }
240 if (mv_abstain)
242
243 for (i = 0; i < mv_ssdirs_count; ++i)
245 mv_ssdirs_count = 0;
246}
#define boolean(value)
Definition bool.qh:9
bool mv_selection_keyboard
int mv_selection
float mv_select_lasttime[MAPVOTE_COUNT]
int mv_flags_start[MAPVOTE_COUNT]
(gt) mv_flags initially
string mv_chosenmap
bool mv_active
float mv_suggester_cachetime
string mv_suggester_cache
entity mv_pk3list
int mv_ownvote
bool gametypevote
const int SF_MV_DETAIL_COUNTS
mv_detail 1
Definition net.qh:12
const int SF_MV_GTV_MAPS
Definition net.qh:15
const int SF_MV_ABSTAIN
mv_abstain is true if this is set
Definition net.qh:11
const int SF_MV_GTV_NOW
Definition net.qh:16
const int SF_MV_DETAIL_WINNER
mv_detail 2
Definition net.qh:13
bool autocvar_hud_cursormode
Definition hud.qh:191
vector mousepos
Definition hud.qh:103
noref float vid_conwidth
Definition draw.qh:7
noref float vid_conheight
Definition draw.qh:8
#define ReadFloat()
Definition net.qh:348
void GameTypeVote_ReadOption(int i)
Definition net.qc:118
void MapVote_ReadOption(int i)
Definition net.qc:89
void MapVote_ReadMask()
Definition net.qc:63
bool mv_abstain
(shared) if abstaining is possible, false in gametype voting
Definition mapvoting.qh:21
int mv_count
(shared) number of maps/gametypes
Definition mapvoting.qh:14
int mv_ssdirs_count
Definition mapvoting.qh:10
int mv_detail
(shared) how much information about the votes/results is revealed
Definition mapvoting.qh:20
string mv_ssdirs[MAPVOTE_SSDIRS_COUNT]
Definition mapvoting.qh:9
int mv_count_real
(shared) number of maps/gametypes, excluding abstain
Definition mapvoting.qh:15
int mv_votes[MAPVOTE_COUNT]
(shared) number of votes for the map/gametype
Definition mapvoting.qh:19
float mv_timeout
Definition mapvoting.qh:23
string string_null
Definition nil.qh:9
#define NULL
Definition post.qh:14
void
Definition self.qh:76
const vector eY
Definition vector.qh:44
const vector eX
Definition vector.qh:43

References autocvar_hud_cursormode, boolean, eX, eY, gametypevote, GameTypeVote_ReadOption(), MapVote_ReadMask(), MapVote_ReadOption(), mousepos, mv_abstain, mv_active, mv_chosenmap, mv_count, mv_count_real, mv_detail, mv_entries, mv_flags, mv_flags_start, mv_ownvote, mv_pk3list, mv_select_lasttime, mv_selection, mv_selection_keyboard, mv_ssdirs, mv_ssdirs_count, mv_suggester_cache, mv_suggester_cachetime, mv_timeout, mv_votes, NULL, ReadByte(), ReadFloat, ReadString, SF_MV_ABSTAIN, SF_MV_DETAIL_COUNTS, SF_MV_DETAIL_WINNER, SF_MV_GTV_MAPS, SF_MV_GTV_NOW, string_null, strzone(), vid_conheight, vid_conwidth, and void.

Referenced by NET_HANDLE().

◆ MapVote_Init_Server()

void MapVote_Init_Server ( )

Definition at line 160 of file net.qc.

161{
162 int i;
163
165 for (i = 0; i < mv_ssdirs_count; ++i)
168 WriteFloat(MSG_ENTITY, mv_timeout);
169
170 if (gametypevote)
171 {
172 WriteByte(MSG_ENTITY, SF_MV_GTV_NOW); // gametypevote_flags: gametype vote
174 }
176 {
177 WriteByte(MSG_ENTITY, SF_MV_GTV_DONE); // gametypevote_flags: map vote but gametype has been chosen via voting screen
178 string voted_gametype_name = (voted_gametype_string == MapInfo_Type_ToString(voted_gametype))
180 : cvar_string(strcat("sv_vote_gametype_", voted_gametype_string, "_name"));
181 WriteString(MSG_ENTITY, voted_gametype_name);
182 }
183 else
184 WriteByte(MSG_ENTITY, SF_MV_GTV_MAPS); // gametypevote_flags: map vote
185
187
188 // Send data for the vote options
190 for (i = 0; i < mv_count_real; ++i)
191 WriteOption(i);
192}
const int SF_MV_GTV_DONE
Definition net.qh:17
#define get_nextmap()
string MapInfo_Type_ToString(Gametype t)
Definition mapinfo.qc:655
void MapVote_WriteOption(int i)
Sends a single map vote option to the client.
Definition net.qc:81
void GameTypeVote_WriteOption(int i)
Sends a single gametype vote option to the client.
Definition net.qc:105
void MapVote_WriteMask()
Definition net.qc:51
Gametype voted_gametype
bool autocvar_sv_vote_gametype
string voted_gametype_string

References autocvar_sv_vote_gametype, cvar_string(), gametypevote, GameTypeVote_WriteOption(), get_nextmap, MapInfo_Type_ToString(), MapInfo_Type_ToText(), MapVote_WriteMask(), MapVote_WriteOption(), MSG_ENTITY, mv_count, mv_count_real, mv_ssdirs, mv_ssdirs_count, mv_timeout, SF_MV_GTV_DONE, SF_MV_GTV_MAPS, SF_MV_GTV_NOW, strcat(), void, voted_gametype, voted_gametype_string, WriteByte(), and WriteString().

Referenced by MapVote_SendEntity().

◆ MapVote_ReadMask()

void MapVote_ReadMask ( )

Definition at line 63 of file net.qc.

64{
65 int b, B, i;
66 for (i = 0; i < mv_count_real; )
67 for (B = ReadByte(), b = BIT(0); b < BIT(8) && i < mv_count_real; b <<= 1, ++i)
68 {
69 if (B & b)
71 else
73 }
74 if (mv_abstain) // make abstain available
76}
#define BIT(n)
Only ever assign into the first 24 bits in QC (so max is BIT(23)).
Definition bits.qh:8
const int GTV_AVAILABLE
Can be voted.
Definition mapvoting.qh:28

References BIT, GTV_AVAILABLE, mv_abstain, mv_count_real, mv_flags, and ReadByte().

Referenced by MapVote_Init_Client(), and NET_HANDLE().

◆ MapVote_ReadOption()

void MapVote_ReadOption ( int i)

Definition at line 89 of file net.qc.

90{
91 TC(int, i);
96
98 mv_preview[i] = false;
100}
void MapVote_CheckPic(string pic, string pk3, int id)

References GTV_AVAILABLE, MapVote_CheckPic(), mv_data, mv_entries, mv_flags, mv_pics, mv_preview, mv_ssdirs, mv_suggester, ReadByte(), ReadString, strcat(), strzone(), and TC.

Referenced by MapVote_Init_Client().

◆ MapVote_ReadPlayerVote()

void MapVote_ReadPlayerVote ( entity voter)

Definition at line 27 of file net.qc.

28{
29 // clear possibly invalid vote
30 if (!(mv_flags[voter.mapvote - 1] & GTV_AVAILABLE))
31 voter.mapvote = 0;
32 // use impulse as new vote
33 if (CS(voter).impulse >= 1 && CS(voter).impulse <= mv_count // valid impulse
34 && (mv_flags[CS(voter).impulse - 1] & GTV_AVAILABLE) // map/gametype is available
35 && !ClientCommand_antispam(voter, strcat("impulse ", itos(CS(voter).impulse)), spamtime, 0.5, 2)) // not spamming
36 {
37 voter.mapvote = CS(voter).impulse;
38 mapvote_ent.SendFlags |= SF_MV_VOTES;
39 }
40 CS(voter).impulse = 0;
41}
bool ClientCommand_antispam(entity this, string command,.float antispam_fld, float antispam_time, int antispam_count)
Returns true if antispam should prevent the command.
Definition cmd.qc:1165
const int SF_MV_VOTES
Definition net.qh:8
#define itos(i)
Definition int.qh:6
float spamtime
Definition net.qc:26
entity mapvote_ent
Definition net.qc:7
float impulse
Definition progsdefs.qc:158
ClientState CS(Client this)
Definition state.qh:47

References ClientCommand_antispam(), CS(), entity(), GTV_AVAILABLE, impulse, itos, mapvote_ent, mv_count, mv_flags, SF_MV_VOTES, spamtime, and strcat().

Referenced by MapVote_Tick().

◆ MapVote_SendEntity()

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

Definition at line 250 of file net.qc.

251{
252 int i;
253 if (!mv_winner_time)
254 sf &= ~SF_MV_WINNER; // no winner yet
255
256 // Pack some extra data into sf
258 if (mv_abstain)
259 sf |= SF_MV_ABSTAIN;
260 if (mv_detail == 1)
262 else if (mv_detail == 2)
264
265 WriteHeader(MSG_ENTITY, ENT_CLIENT_MAPVOTE);
267 if (sf & SF_MV_INIT)
269 else if (sf & SF_MV_MASK) // else if, since init already writes the mask
271
272 if (sf & SF_MV_VOTES)
273 {
274 if (mv_detail)
275 {
276 int i;
277 for (i = 0; i < mv_count; ++i)
278 if (mv_flags[i] & GTV_AVAILABLE)
280
281 if (mv_detail == 2) // tell the client what the tie winner will be
282 i = mv_ranked[0];
283 else if (mv_votes[mv_ranked[0]] == 0) // no votes yet, don't draw a winner (-1)
284 i = -1;
285 else // figure out winners yourself (-2)
286 i = -2;
287 WriteByte(MSG_ENTITY, i + 2);
288 }
289
290 WriteByte(MSG_ENTITY, to.mapvote);
291 }
292
293 if (sf & SF_MV_WINNER)
295
296 return true;
297}
float mv_winner_time
const int SF_MV_MASK
Definition net.qh:7
const int SF_MV_INIT
Definition net.qh:6
const int SF_MV_WINNER
Definition net.qh:9
#define WriteHeader(to, id)
Definition net.qh:265
void MapVote_Init_Server()
Definition net.qc:160
int mv_winner
Definition mapvoting.qh:24
int mv_ranked[MAPVOTE_COUNT]
(shared) maps/gametypes ranked by most votes, first = most

References entity(), GTV_AVAILABLE, MapVote_Init_Server(), MapVote_WriteMask(), MSG_ENTITY, mv_abstain, mv_count, mv_detail, mv_flags, mv_ranked, mv_votes, mv_winner, mv_winner_time, SF_MV_ABSTAIN, SF_MV_DETAIL_COUNTS, SF_MV_DETAIL_WINNER, SF_MV_INIT, SF_MV_MASK, SF_MV_VOTES, SF_MV_WINNER, WriteByte(), and WriteHeader.

Referenced by MapVote_Spawn().

◆ MapVote_Spawn()

void MapVote_Spawn ( )

Definition at line 8 of file net.qc.

9{
11}
void Net_LinkEntity(entity e, bool docull, float dt, bool(entity this, entity to, int sendflags) sendfunc)
Definition net.qh:167
bool MapVote_SendEntity(entity this, entity to, int sf)
Definition net.qc:250

References mapvote_ent, MapVote_SendEntity(), and Net_LinkEntity().

Referenced by GameTypeVote_Start(), and MapVote_Init().

◆ MapVote_TouchMask()

void MapVote_TouchMask ( )

Definition at line 13 of file net.qc.

14{
15 mapvote_ent.SendFlags |= SF_MV_MASK;
16}

References mapvote_ent, and SF_MV_MASK.

Referenced by MapVote_CheckRules_decide().

◆ MapVote_Winner()

void MapVote_Winner ( int mappos)

Definition at line 17 of file net.qc.

18{
19 mapvote_ent.SendFlags |= SF_MV_WINNER;
21 mv_winner = mappos;
22}
float time

References mapvote_ent, mv_winner, mv_winner_time, SF_MV_WINNER, and time.

Referenced by MapVote_Finished().

◆ MapVote_WriteMask()

void MapVote_WriteMask ( )

Definition at line 51 of file net.qc.

52{
53 for (int b, B, i = 0; i < mv_count_real; )
54 {
55 B = 0;
56 for (b = BIT(0); b < BIT(8) && i < mv_count_real; b <<= 1, ++i)
57 if (mv_flags[i] & GTV_AVAILABLE)
58 B |= b;
60 }
61}

References BIT, GTV_AVAILABLE, MSG_ENTITY, mv_count_real, mv_flags, and WriteByte().

Referenced by MapVote_Init_Server(), and MapVote_SendEntity().

◆ MapVote_WriteOption()

void MapVote_WriteOption ( int i)

Sends a single map vote option to the client.

Definition at line 81 of file net.qc.

82{
87}
string mv_pakfile[MAPVOTE_COUNT]
(maps) pk3 file location
bool mv_show_suggester
(maps) whether to show suggesters, only for maps since you can't suggest gametypes
int mv_ssdir_i[MAPVOTE_COUNT]
(shared) where to look for screenshots (mv_ssdirs index), set to 0 for gametype voting

References MSG_ENTITY, mv_entries, mv_pakfile, mv_show_suggester, mv_ssdir_i, mv_suggester, WriteByte(), and WriteString().

Referenced by MapVote_Init_Server().

◆ MapVote_WritePicture()

void MapVote_WritePicture ( entity to,
int id )

Definition at line 342 of file net.qc.

343{
344 msg_entity = to;
345 WriteHeader(MSG_ONE, TE_CSQC_PICTURE);
346 WriteByte(MSG_ONE, id);
347 WritePicture(MSG_ONE, strcat(mv_ssdirs[mv_ssdir_i[id]], "/", mv_entries[id]), 3072);
348}
float MSG_ONE
Definition menudefs.qc:56
entity msg_entity
Definition progsdefs.qc:63

References entity(), msg_entity, MSG_ONE, mv_entries, mv_ssdir_i, mv_ssdirs, strcat(), WriteByte(), and WriteHeader.

Referenced by ClientCommand_mv_getpicture().

◆ MapVote_WritePlayerVote()

void MapVote_WritePlayerVote ( int index)

Definition at line 43 of file net.qc.

44{
45 TC(int, index);
46 localcmd("\nimpulse ", itos(index + 1), "\n");
47}
void localcmd(string command,...)

References itos, localcmd(), and TC.

Referenced by MapVote_InputEvent().

◆ NET_HANDLE() [1/2]

NET_HANDLE ( ENT_CLIENT_MAPVOTE ,
bool isNew )

Definition at line 299 of file net.qc.

300{
301 int sf = ReadByte();
302
303 if (sf & SF_MV_INIT)
305 else if (sf & SF_MV_MASK)
306 {
309 }
310
311 if (sf & SF_MV_VOTES)
312 {
313 for (int i = 0; i < mv_count; ++i)
314 {
315 if (mv_flags[i] & GTV_AVAILABLE)
316 {
317 if (mv_detail)
318 mv_votes[i] = ReadByte();
319 else
320 mv_votes[i] = 0;
321 }
322 else
323 mv_votes[i] = -1;
324 }
325 if (mv_detail)
326 mv_tie_winner = ReadByte() - 2;
327
328 mv_ownvote = ReadByte() - 1;
329 }
330
331 if (sf & SF_MV_WINNER)
332 {
335 }
336
337 return true;
338}
int mv_tie_winner
void MapVote_Init_Client(int sf)
Definition net.qc:194
float mv_reduce_time
Definition mapvoting.qh:22

References GTV_AVAILABLE, MapVote_Init_Client(), MapVote_ReadMask(), mv_count, mv_detail, mv_flags, mv_ownvote, mv_reduce_time, mv_tie_winner, mv_votes, mv_winner, mv_winner_time, ReadByte(), SF_MV_INIT, SF_MV_MASK, SF_MV_VOTES, SF_MV_WINNER, and time.

◆ NET_HANDLE() [2/2]

NET_HANDLE ( TE_CSQC_PICTURE ,
bool isNew )

Definition at line 350 of file net.qc.

351{
352 int type = ReadByte();
353 mv_preview[type] = true;
354 mv_pics[type] = strzone(ReadPicture());
355 return true;
356}

References mv_pics, mv_preview, ReadByte(), and strzone().

Variable Documentation

◆ mapvote_ent

entity mapvote_ent

Definition at line 7 of file net.qc.

Referenced by MapVote_ReadPlayerVote(), MapVote_Spawn(), MapVote_TouchMask(), and MapVote_Winner().

◆ spamtime

float spamtime

Definition at line 26 of file net.qc.

Referenced by MapVote_ReadPlayerVote().