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

Method Info_SetValueForKey

qcommon/src/main/java/jake2/qcommon/Info.java:57–94  ·  view source on GitHub ↗

Sets a value for a key in the user info string.

(String s, String key, String value)

Source from the content-addressed store, hash-verified

55 * Sets a value for a key in the user info string.
56 */
57 public static String Info_SetValueForKey(String s, String key, String value) {
58
59 if (value == null || value.length() == 0)
60 return s;
61
62 if (key.indexOf('\\') != -1 || value.indexOf('\\') != -1) {
63 Com.Printf("Can't use keys or values with a \\\n");
64 return s;
65 }
66
67 if (key.indexOf(';') != -1) {
68 Com.Printf("Can't use keys or values with a semicolon\n");
69 return s;
70 }
71
72 if (key.indexOf('"') != -1 || value.indexOf('"') != -1) {
73 Com.Printf("Can't use keys or values with a \"\n");
74 return s;
75 }
76
77 if (key.length() > Defines.MAX_INFO_KEY - 1
78 || value.length() > Defines.MAX_INFO_KEY - 1) {
79 Com.Printf("Keys and values must be < 64 characters.\n");
80 return s;
81 }
82
83 StringBuffer sb = new StringBuffer(Info_RemoveKey(s, key));
84
85 if (sb.length() + 2 + key.length() + value.length() > Defines.MAX_INFO_STRING) {
86
87 Com.Printf("Info string length exceeded\n");
88 return s;
89 }
90
91 sb.append('\\').append(key).append('\\').append(value);
92
93 return sb.toString();
94 }
95
96 /**
97 * Removes a key and value from an info string.

Callers 3

ClientConnectMethod · 0.95
SVC_DirectConnectMethod · 0.95
BitInfoMethod · 0.95

Calls 3

PrintfMethod · 0.95
Info_RemoveKeyMethod · 0.95
toStringMethod · 0.45

Tested by

no test coverage detected