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

Go to the source code of this file.

Functions

void MX_Forget (string room)
void MX_JLF_ (entity fh, entity pass, int status)
void MX_Join (string room)
void MX_Leave (string room)
void MX_Messages (string from)
void MX_Messages_ (entity fh, entity pass, int status)
void MX_Nick (string name)
void MX_Nick_ (entity fh, entity pass, int status)
void MX_Say (string body)
void MX_Say_ (entity fh, entity pass, int status)
void MX_Sync (string since)
void MX_Sync_ (entity fh, entity pass, int status)
void MX_Typing (bool state)
void MX_Typing_ (entity fh, entity pass, int status)

Variables

string message

Function Documentation

◆ MX_Forget()

void MX_Forget ( string room)

Definition at line 149 of file matrix.qc.

150{
152 return;
154 sprintf("%s/_matrix/client/r0/rooms/%s/forget?access_token=%s", autocvar_matrix_server, matrix_room, matrix_access_token),
156 MX_JLF_,
157 NULL
158 );
159}
const float FILE_WRITE
void MX_JLF_(entity fh, entity pass, int status)
Definition matrix.qc:160
string matrix_access_token
Definition matrix.qh:5
string matrix_room
Definition matrix.qh:6
string autocvar_matrix_server
Definition matrix.qh:3
#define NULL
Definition post.qh:14
ERASEABLE void url_single_fopen(string url, int mode, url_ready_func rdy, entity pass)
Definition urllib.qc:90

References autocvar_matrix_server, FILE_WRITE, matrix_access_token, matrix_room, MX_JLF_(), NULL, and url_single_fopen().

Referenced by GENERIC_COMMAND().

◆ MX_JLF_()

void MX_JLF_ ( entity fh,
entity pass,
int status )

Definition at line 160 of file matrix.qc.

161{
162 switch (status)
163 {
165 {
166 fh.url_content_type = "application/json";
167 url_fputs(fh, sprintf("{%s}", pass.message));
168 url_fclose(fh);
169 break;
170 }
171 }
172}
#define pass(name, colormin, colormax)
ERASEABLE void url_fputs(entity e, string s)
Definition urllib.qc:312
ERASEABLE void url_fclose(entity e)
Definition urllib.qc:209
const float URL_READY_CANWRITE
Definition urllib.qh:16

References entity(), pass, url_fclose(), url_fputs(), and URL_READY_CANWRITE.

Referenced by MX_Forget(), MX_Join(), and MX_Leave().

◆ MX_Join()

void MX_Join ( string room)

Definition at line 127 of file matrix.qc.

128{
130 return;
132 sprintf("%s/_matrix/client/r0/rooms/%s/join?access_token=%s", autocvar_matrix_server, matrix_room, matrix_access_token),
134 MX_JLF_,
135 NULL
136 );
137}

References autocvar_matrix_server, FILE_WRITE, matrix_access_token, matrix_room, MX_JLF_(), NULL, and url_single_fopen().

Referenced by GENERIC_COMMAND().

◆ MX_Leave()

void MX_Leave ( string room)

Definition at line 138 of file matrix.qc.

139{
141 return;
143 sprintf("%s/_matrix/client/r0/rooms/%s/leave?access_token=%s", autocvar_matrix_server, matrix_room, matrix_access_token),
145 MX_JLF_,
146 NULL
147 );
148}

References autocvar_matrix_server, FILE_WRITE, matrix_access_token, matrix_room, MX_JLF_(), NULL, and url_single_fopen().

Referenced by GENERIC_COMMAND().

◆ MX_Messages()

void MX_Messages ( string from)

Definition at line 37 of file matrix.qc.

38{
40 return;
41 string s = sprintf("%s/_matrix/client/r0/events?room_id=%s&limit=50&timeout=30000&from=%s&access_token=%s", autocvar_matrix_server, matrix_room, from, matrix_access_token);
43 s,
46 NULL
47 );
48}
const float FILE_READ
void MX_Messages_(entity fh, entity pass, int status)
Definition matrix.qc:49

References autocvar_matrix_server, FILE_READ, matrix_access_token, matrix_room, MX_Messages_(), NULL, and url_single_fopen().

Referenced by GENERIC_COMMAND(), and MX_Messages_().

◆ MX_Messages_()

void MX_Messages_ ( entity fh,
entity pass,
int status )

Definition at line 49 of file matrix.qc.

50{
51 switch (status)
52 {
53 default:
54 {
55 LOG_WARNF("status: %d", status);
56 break;
57 }
59 break;
61 {
62 string json = "";
63 for (string s; (s = url_fgets(fh)); )
64 json = strcat(json, s, "\n");
65 url_fclose(fh);
66 int buf = json_parse(json, _json_parse_object);
67 EXPECT_NE(-1, buf);
68 for (int i = 0, n = stof(json_get(buf, "chunk.length")); i < n; ++i)
69 MX_Handle(buf, sprintf("chunk.%d", i));
70 MX_Messages(json_get(buf, "end"));
71 break;
72 }
73 }
74}
ERASEABLE int json_parse(string in, bool() func)
Definition json.qc:266
ERASEABLE string json_get(int buf, string key)
Definition json.qc:323
ERASEABLE bool _json_parse_object()
Parse a json object.
Definition json.qc:21
void MX_Messages(string from)
Definition matrix.qc:37
#define LOG_WARNF(...)
Definition log.qh:59
var void MX_Handle(int buf, string ancestor)
Definition matrix.qc:3
float stof(string val,...)
strcat(_("^F4Countdown stopped!"), "\n^BG", _("Teams are too unbalanced."))
#define EXPECT_NE(val1, val2)
Definition test.qh:53
ERASEABLE string url_fgets(entity e)
Definition urllib.qc:291
const float URL_READY_CLOSED
Definition urllib.qh:15
const float URL_READY_CANREAD
Definition urllib.qh:17

References _json_parse_object(), entity(), EXPECT_NE, json_get(), json_parse(), LOG_WARNF, MX_Handle(), MX_Messages(), pass, stof(), strcat(), url_fclose(), url_fgets(), URL_READY_CANREAD, and URL_READY_CLOSED.

Referenced by MX_Messages().

◆ MX_Nick()

void MX_Nick ( string name)

Definition at line 6 of file matrix.qc.

7{
9 return;
10 entity pass = new_pure(mx);
11 pass.message = name;
13 sprintf("%s/_matrix/client/r0/profile/%s/displayname?access_token=%s", autocvar_matrix_server, matrix_user, matrix_access_token),
16 pass
17 );
18}
var entity(vector mins, vector maxs,.entity tofield) findbox_tofield_OrFallback
void MX_Nick_(entity fh, entity pass, int status)
Definition matrix.qc:19
string matrix_user
Definition matrix.qh:4
string name
Definition menu.qh:30
#define new_pure(class)
purely logical entities (not linked to the area grid)
Definition oo.qh:66

References autocvar_matrix_server, entity(), FILE_WRITE, matrix_access_token, matrix_user, MX_Nick_(), name, new_pure, pass, and url_single_fopen().

Referenced by GENERIC_COMMAND().

◆ MX_Nick_()

void MX_Nick_ ( entity fh,
entity pass,
int status )

Definition at line 19 of file matrix.qc.

20{
21 switch (status)
22 {
24 {
25 fh.url_verb = "PUT";
26 fh.url_content_type = "application/json";
27 url_fputs(fh, sprintf("{\"displayname\": \"%s\"}", pass.message));
28 delete(pass);
29 url_fclose(fh);
30 break;
31 }
32 }
33}

References entity(), pass, url_fclose(), url_fputs(), and URL_READY_CANWRITE.

Referenced by MX_Nick().

◆ MX_Say()

void MX_Say ( string body)

Definition at line 207 of file matrix.qc.

208{
210 return;
211 static int txnid;
212 entity pass = new_pure(mx);
213 pass.message = strzone(body);
215 sprintf("%s/_matrix/client/r0/rooms/%s/send/m.room.message/%d?access_token=%s", autocvar_matrix_server, matrix_room, ++txnid, matrix_access_token),
217 MX_Say_,
218 pass
219 );
220}
void MX_Say_(entity fh, entity pass, int status)
Definition matrix.qc:221
string strzone(string s)

References autocvar_matrix_server, entity(), FILE_WRITE, matrix_access_token, matrix_room, MX_Say_(), new_pure, pass, strzone(), and url_single_fopen().

Referenced by GENERIC_COMMAND(), and Say().

◆ MX_Say_()

void MX_Say_ ( entity fh,
entity pass,
int status )

Definition at line 221 of file matrix.qc.

222{
223 switch (status)
224 {
226 {
227 fh.url_verb = "PUT";
228 fh.url_content_type = "application/json";
229 url_fputs(fh, sprintf("{\"msgtype\": \"m.text\", \"body\": \"%s\"}", pass.message));
230 strfree(pass.message);
231 delete(pass);
232 url_fclose(fh);
233 break;
234 }
235 }
236}
#define strfree(this)
Definition string.qh:57

References entity(), pass, strfree, url_fclose(), url_fputs(), and URL_READY_CANWRITE.

Referenced by MX_Say().

◆ MX_Sync()

void MX_Sync ( string since)

Definition at line 78 of file matrix.qc.

79{
81 return;
82 string s = strcat(autocvar_matrix_server, "/_matrix/client/r0/sync?");
83 if (since)
84 s = strcat(s,
85 "since=", since, "&",
86 "timeout=30000&",
87 sprintf("filter={\"account_data\":{\"types\":[]},\"presence\":{\"types\":[]},\"room\":{\"rooms\":[\"%s\"]}}&", matrix_room)
88 );
89 else
90 s = strcat(s,
91 "timeout=0&",
92 "filter={\"account_data\":{\"types\":[]},\"presence\":{\"types\":[]},\"room\":{\"rooms\":[]}}&"
93 );
94 s = strcat(s, "access_token=", matrix_access_token);
96}
void MX_Sync_(entity fh, entity pass, int status)
Definition matrix.qc:97

References autocvar_matrix_server, FILE_READ, matrix_access_token, matrix_room, MX_Sync_(), NULL, strcat(), and url_single_fopen().

Referenced by GENERIC_COMMAND(), and MX_Sync_().

◆ MX_Sync_()

void MX_Sync_ ( entity fh,
entity pass,
int status )

Definition at line 97 of file matrix.qc.

98{
99 switch (status)
100 {
101 default:
102 {
103 LOG_WARNF("status: %d", status);
104 break;
105 }
106 case URL_READY_CLOSED:
107 break;
109 {
110 string json = "";
111 for (string s; (s = url_fgets(fh)); )
112 json = strcat(json, s, "\n");
113 url_fclose(fh);
114 int buf = json_parse(json, _json_parse_object);
115 EXPECT_NE(-1, buf);
116 string arr = sprintf("rooms.join.%s.timeline.events", matrix_room);
117 for (int i = 0, n = stof(json_get(buf, sprintf("%s.length", arr))); i < n; ++i)
118 MX_Handle(buf, sprintf("%s.%d", arr, i));
119 MX_Sync(json_get(buf, "next_batch"));
120 break;
121 }
122 }
123}
void MX_Sync(string since)
Definition matrix.qc:78

References _json_parse_object(), entity(), EXPECT_NE, json_get(), json_parse(), LOG_WARNF, matrix_room, MX_Handle(), MX_Sync(), pass, stof(), strcat(), url_fclose(), url_fgets(), URL_READY_CANREAD, and URL_READY_CLOSED.

Referenced by MX_Sync().

◆ MX_Typing()

void MX_Typing ( bool state)

Definition at line 176 of file matrix.qc.

177{
179 return;
180 entity pass = new_pure(mx);
181 pass.message = state ? "true" : "false";
183 sprintf("%s/_matrix/client/r0/rooms/%s/typing/%s?access_token=%s", autocvar_matrix_server, matrix_room, matrix_user, matrix_access_token),
186 pass
187 );
188}
int state
void MX_Typing_(entity fh, entity pass, int status)
Definition matrix.qc:189

References autocvar_matrix_server, entity(), FILE_WRITE, matrix_access_token, matrix_room, matrix_user, MX_Typing_(), new_pure, pass, state, and url_single_fopen().

Referenced by GENERIC_COMMAND().

◆ MX_Typing_()

void MX_Typing_ ( entity fh,
entity pass,
int status )

Definition at line 189 of file matrix.qc.

190{
191 switch (status)
192 {
194 {
195 fh.url_verb = "PUT";
196 fh.url_content_type = "application/json";
197 url_fputs(fh, sprintf("{\"typing\": %s, \"timeout\": 30000}", pass.message));
198 delete(pass);
199 url_fclose(fh);
200 break;
201 }
202 }
203}

References entity(), pass, url_fclose(), url_fputs(), and URL_READY_CANWRITE.

Referenced by MX_Typing().

Variable Documentation

◆ message

string message

Definition at line 3 of file matrix.qc.