Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
net.qc
Go to the documentation of this file.
1#include "net.qh"
2
3#ifdef SVQC
5
6bool MapVote_SendEntity(entity this, entity to, int sf);
12
14{
15 mapvote_ent.SendFlags |= SF_MV_MASK;
16}
17void MapVote_Winner(int mappos)
18{
19 mapvote_ent.SendFlags |= SF_MV_WINNER;
21 mv_winner = mappos;
22}
23#endif // SVQC
24
25#ifdef SVQC
26.float spamtime; // Reused here
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}
42#elifdef CSQC
44{
45 TC(int, index);
46 localcmd("\nimpulse ", itos(index + 1), "\n");
47}
48#endif
49
50#ifdef SVQC
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}
62#elifdef CSQC
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}
77#endif
78
79#ifdef SVQC
88#elifdef CSQC
90{
91 TC(int, i);
96
98 mv_preview[i] = false;
100}
101#endif
102
103#ifdef SVQC
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}
117#elifdef CSQC
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}
157#endif
158
159#ifdef SVQC
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}
193#elifdef CSQC
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}
247#endif
248
249#ifdef SVQC
250bool MapVote_SendEntity(entity this, entity to, int sf)
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}
298#elifdef CSQC
299NET_HANDLE(ENT_CLIENT_MAPVOTE, bool isNew)
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}
339#endif
340
341#ifdef SVQC
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}
349#elifdef CSQC
350NET_HANDLE(TE_CSQC_PICTURE, bool isNew)
351{
352 int type = ReadByte();
353 mv_preview[type] = true;
354 mv_pics[type] = strzone(ReadPicture());
355 return true;
356}
357#endif
#define BIT(n)
Only ever assign into the first 24 bits in QC (so max is BIT(23)).
Definition bits.qh:8
#define boolean(value)
Definition bool.qh:9
var entity(vector mins, vector maxs,.entity tofield) findbox_tofield_OrFallback
void MapVote_CheckPic(string pic, string pk3, int id)
bool PreviewExists(string name)
bool mv_selection_keyboard
int mv_tie_winner
int mv_selection
float mv_select_lasttime[MAPVOTE_COUNT]
int mv_flags_start[MAPVOTE_COUNT]
(gt) mv_flags initially
float mv_winner_time
string mv_chosenmap
bool mv_active
float mv_suggester_cachetime
string mv_suggester_cache
string mv_desc[MAPVOTE_COUNT]
(gt) gametype description
entity mv_pk3list
int mv_ownvote
string mv_data[MAPVOTE_COUNT]
(shared) map pk3 name/gametype human readable name
bool gametypevote
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
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_DETAIL_COUNTS
mv_detail 1
Definition net.qh:12
const int SF_MV_MASK
Definition net.qh:7
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_DONE
Definition net.qh:17
const int SF_MV_GTV_NOW
Definition net.qh:16
const int SF_MV_INIT
Definition net.qh:6
const int SF_MV_DETAIL_WINNER
mv_detail 2
Definition net.qh:13
const int SF_MV_WINNER
Definition net.qh:9
const int SF_MV_VOTES
Definition net.qh:8
float time
#define strlen
WriteString(chan, ent.netname)
WriteByte(chan, ent.angles.y/DEC_FACTOR)
bool autocvar_hud_cursormode
Definition hud.qh:191
vector mousepos
Definition hud.qh:103
#define itos(i)
Definition int.qh:6
#define get_nextmap()
#define TC(T, sym)
Definition _all.inc:82
noref float vid_conwidth
Definition draw.qh:7
noref float vid_conheight
Definition draw.qh:8
#define ReadFloat()
Definition net.qh:348
#define NET_HANDLE(id, param)
Definition net.qh:15
const int MSG_ENTITY
Definition net.qh:156
#define WriteHeader(to, id)
Definition net.qh:265
void Net_LinkEntity(entity e, bool docull, float dt, bool(entity this, entity to, int sendflags) sendfunc)
Definition net.qh:167
int ReadByte()
string MapInfo_Type_ToString(Gametype t)
Definition mapinfo.qc:655
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
void MapVote_ReadPlayerVote(entity voter)
Definition net.qc:27
void MapVote_WriteOption(int i)
Sends a single map vote option to the client.
Definition net.qc:81
bool MapVote_SendEntity(entity this, entity to, int sf)
Definition net.qc:250
void GameTypeVote_ReadOption(int i)
Definition net.qc:118
float spamtime
Definition net.qc:26
void MapVote_TouchMask()
Definition net.qc:13
void GameTypeVote_WriteOption(int i)
Sends a single gametype vote option to the client.
Definition net.qc:105
void MapVote_Winner(int mappos)
Definition net.qc:17
void MapVote_Init_Server()
Definition net.qc:160
void MapVote_ReadOption(int i)
Definition net.qc:89
void MapVote_WritePicture(entity to, int id)
Definition net.qc:342
void MapVote_WritePlayerVote(int index)
Definition net.qc:43
void MapVote_Spawn()
Definition net.qc:8
void MapVote_Init_Client(int sf)
Definition net.qc:194
entity mapvote_ent
Definition net.qc:7
void MapVote_WriteMask()
Definition net.qc:51
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
const int GTV_CUSTOM
Custom entry.
Definition mapvoting.qh:29
int mv_ssdirs_count
Definition mapvoting.qh:10
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
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
float mv_reduce_time
Definition mapvoting.qh:22
int mv_winner
Definition mapvoting.qh:24
int mv_count_real
(shared) number of maps/gametypes, excluding abstain
Definition mapvoting.qh:15
const int GTV_AVAILABLE
Can be voted.
Definition mapvoting.qh:28
int mv_votes[MAPVOTE_COUNT]
(shared) number of votes for the map/gametype
Definition mapvoting.qh:19
string mv_suggester[MAPVOTE_COUNT]
(maps) .netname of the player who suggested the map
Definition mapvoting.qh:17
float mv_timeout
Definition mapvoting.qh:23
string name
Definition menu.qh:30
void localcmd(string command,...)
float MSG_ONE
Definition menudefs.qc:56
string precache_pic(string name,...)
const string cvar_string(string name)
string strzone(string s)
string string_null
Definition nil.qh:9
strcat(_("^F4Countdown stopped!"), "\n^BG", _("Teams are too unbalanced."))
#define NULL
Definition post.qh:14
entity msg_entity
Definition progsdefs.qc:63
float impulse
Definition progsdefs.qc:158
void
Definition self.qh:76
ClientState CS(Client this)
Definition state.qh:47
Gametype voted_gametype
bool autocvar_sv_vote_gametype
int mv_ranked[MAPVOTE_COUNT]
(shared) maps/gametypes ranked by most votes, first = most
string mv_pakfile[MAPVOTE_COUNT]
(maps) pk3 file location
string voted_gametype_string
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
const vector eY
Definition vector.qh:44
const vector eX
Definition vector.qh:43