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 135 of file matrix.qc.

136{
137 if (!matrix_access_token) return;
139 sprintf("%s/_matrix/client/r0/rooms/%s/forget?access_token=%s", autocvar_matrix_server, matrix_room, matrix_access_token),
141 MX_JLF_,
142 NULL
143 );
144}
const float FILE_WRITE
void MX_JLF_(entity fh, entity pass, int status)
Definition matrix.qc:145
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:87

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 145 of file matrix.qc.

146{
147 switch (status) {
148 case URL_READY_CANWRITE: {
149 fh.url_content_type = "application/json";
150 url_fputs(fh, sprintf("{%s}", pass.message));
151 url_fclose(fh);
152 break;
153 }
154 }
155}
#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:207
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 115 of file matrix.qc.

116{
117 if (!matrix_access_token) return;
119 sprintf("%s/_matrix/client/r0/rooms/%s/join?access_token=%s", autocvar_matrix_server, matrix_room, matrix_access_token),
121 MX_JLF_,
122 NULL
123 );
124}

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 125 of file matrix.qc.

126{
127 if (!matrix_access_token) return;
129 sprintf("%s/_matrix/client/r0/rooms/%s/leave?access_token=%s", autocvar_matrix_server, matrix_room, matrix_access_token),
131 MX_JLF_,
132 NULL
133 );
134}

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 34 of file matrix.qc.

35{
36 if (!matrix_access_token) return;
37 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);
39 s,
42 NULL
43 );
44}
const float FILE_READ
void MX_Messages_(entity fh, entity pass, int status)
Definition matrix.qc:45

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 45 of file matrix.qc.

46{
47 switch (status) {
48 default: {
49 LOG_WARNF("status: %d", status);
50 break;
51 }
52 case URL_READY_CLOSED: break;
53 case URL_READY_CANREAD: {
54 string json = "";
55 for (string s; (s = url_fgets(fh)); ) { json = strcat(json, s, "\n"); }
56 url_fclose(fh);
57 int buf = json_parse(json, _json_parse_object);
58 EXPECT_NE(-1, buf);
59 for (int i = 0, n = stof(json_get(buf, "chunk.length")); i < n; ++i) {
60 MX_Handle(buf, sprintf("chunk.%d", i));
61 }
62 MX_Messages(json_get(buf, "end"));
63 break;
64 }
65 }
66}
ERASEABLE int json_parse(string in, bool() func)
Definition json.qc:230
ERASEABLE string json_get(int buf, string key)
Definition json.qc:276
bool _json_parse_object()
parse a json object
Definition json.qc:36
void MX_Messages(string from)
Definition matrix.qc:34
#define LOG_WARNF(...)
Definition log.qh:62
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:52
ERASEABLE string url_fgets(entity e)
Definition urllib.qc:287
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{
8 if (!matrix_access_token) return;
9 entity pass = new_pure(mx);
10 pass.message = name;
12 sprintf("%s/_matrix/client/r0/profile/%s/displayname?access_token=%s", autocvar_matrix_server, matrix_user, matrix_access_token),
15 pass
16 );
17}
var entity(vector mins, vector maxs,.entity tofield) findbox_tofield_OrFallback
void MX_Nick_(entity fh, entity pass, int status)
Definition matrix.qc:18
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:67

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 18 of file matrix.qc.

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

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 187 of file matrix.qc.

188{
189 if (!matrix_access_token) return;
190 static int txnid;
191 entity pass = new_pure(mx);
192 pass.message = strzone(body);
194 sprintf("%s/_matrix/client/r0/rooms/%s/send/m.room.message/%d?access_token=%s", autocvar_matrix_server, matrix_room, ++txnid, matrix_access_token),
196 MX_Say_,
197 pass
198 );
199}
void MX_Say_(entity fh, entity pass, int status)
Definition matrix.qc:200
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 200 of file matrix.qc.

201{
202 switch (status) {
203 case URL_READY_CANWRITE: {
204 fh.url_verb = "PUT";
205 fh.url_content_type = "application/json";
206 url_fputs(fh, sprintf("{\"msgtype\": \"m.text\", \"body\": \"%s\"}", pass.message));
207 strfree(pass.message);
208 delete(pass);
209 url_fclose(fh);
210 break;
211 }
212 }
213}
#define strfree(this)
Definition string.qh:59

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 70 of file matrix.qc.

71{
72 if (!matrix_access_token) return;
73 string s = strcat(autocvar_matrix_server, "/_matrix/client/r0/sync?");
74 if (since) {
75 s = strcat(s,
76 "since=", since, "&",
77 "timeout=30000&",
78 sprintf("filter={\"account_data\":{\"types\":[]},\"presence\":{\"types\":[]},\"room\":{\"rooms\":[\"%s\"]}}&", matrix_room)
79 );
80 } else {
81 s = strcat(s,
82 "timeout=0&",
83 "filter={\"account_data\":{\"types\":[]},\"presence\":{\"types\":[]},\"room\":{\"rooms\":[]}}&"
84 );
85 }
86 s = strcat(s, "access_token=", matrix_access_token);
88}
void MX_Sync_(entity fh, entity pass, int status)
Definition matrix.qc:89

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 89 of file matrix.qc.

90{
91 switch (status) {
92 default: {
93 LOG_WARNF("status: %d", status);
94 break;
95 }
96 case URL_READY_CLOSED: break;
97 case URL_READY_CANREAD: {
98 string json = "";
99 for (string s; (s = url_fgets(fh)); ) { json = strcat(json, s, "\n"); }
100 url_fclose(fh);
101 int buf = json_parse(json, _json_parse_object);
102 EXPECT_NE(-1, buf);
103 string arr = sprintf("rooms.join.%s.timeline.events", matrix_room);
104 for (int i = 0, n = stof(json_get(buf, sprintf("%s.length", arr))); i < n; ++i) {
105 MX_Handle(buf, sprintf("%s.%d", arr, i));
106 }
107 MX_Sync(json_get(buf, "next_batch"));
108 break;
109 }
110 }
111}
void MX_Sync(string since)
Definition matrix.qc:70

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 159 of file matrix.qc.

160{
161 if (!matrix_access_token) return;
162 entity pass = new_pure(mx);
163 pass.message = state ? "true" : "false";
165 sprintf("%s/_matrix/client/r0/rooms/%s/typing/%s?access_token=%s", autocvar_matrix_server, matrix_room, matrix_user, matrix_access_token),
168 pass
169 );
170}
int state
void MX_Typing_(entity fh, entity pass, int status)
Definition matrix.qc:171

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 171 of file matrix.qc.

172{
173 switch (status) {
174 case URL_READY_CANWRITE: {
175 fh.url_verb = "PUT";
176 fh.url_content_type = "application/json";
177 url_fputs(fh, sprintf("{\"typing\": %s, \"timeout\": 30000}", pass.message));
178 delete(pass);
179 url_fclose(fh);
180 break;
181 }
182 }
183}

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.