MCPcopy Create free account
hub / github.com/demoth/jake2 / Set2

Method Set2

qcommon/src/main/java/jake2/qcommon/exec/Cvar.java:208–274  ·  view source on GitHub ↗

Gereric set function, sets the value of the variable, with forcing its even possible to override the variables write protection.

(String var_name, String value, boolean force)

Source from the content-addressed store, hash-verified

206 * override the variables write protection.
207 */
208 cvar_t Set2(String var_name, String value, boolean force) {
209
210 cvar_t var = FindVar(var_name);
211 if (var == null) {
212 // create it
213 return Get(var_name, value, 0);
214 }
215
216 if ((var.flags & (CVAR_USERINFO | CVAR_SERVERINFO)) != 0) {
217 if (invalidInfoString(value)) {
218 Com.Printf("invalid info cvar value\n");
219 return var;
220 }
221 }
222
223 if (!force) {
224 if ((var.flags & CVAR_NOSET) != 0) {
225 Com.Printf(var_name + " is write protected.\n");
226 return var;
227 }
228
229 if ((var.flags & CVAR_LATCH) != 0) {
230 if (var.latched_string != null) {
231 if (value.equals(var.latched_string))
232 return var;
233 var.latched_string = null;
234 } else {
235 if (value.equals(var.string))
236 return var;
237 }
238
239 if (Globals.server_state != ServerStates.SS_DEAD) {
240 Com.Printf(var_name + " will be changed for next game.\n");
241 var.latched_string = value;
242 } else {
243 var.string = value;
244 var.value = Lib.atof(var.string);
245 if (var.name.equals("game")) {
246 FS.SetGamedir(var.string);
247 FS.ExecAutoexec();
248 }
249 }
250 return var;
251 }
252 } else {
253 if (var.latched_string != null) {
254 var.latched_string = null;
255 }
256 }
257
258 if (value.equals(var.string))
259 return var; // not changed
260
261 var.modified = true;
262
263 if ((var.flags & CVAR_USERINFO) != 0)
264 Globals.userinfo_modified = true; // transmit at next oportunity
265

Callers 2

SetMethod · 0.95
ForceSetMethod · 0.95

Calls 8

FindVarMethod · 0.95
GetMethod · 0.95
invalidInfoStringMethod · 0.95
PrintfMethod · 0.95
atofMethod · 0.95
SetGamedirMethod · 0.95
ExecAutoexecMethod · 0.95
equalsMethod · 0.45

Tested by

no test coverage detected