Xonotic
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.

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

Referenced by GENERIC_COMMAND().

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),
140  FILE_WRITE,
141  MX_JLF_,
142  NULL
143  );
144 }
string matrix_access_token
Definition: matrix.qh:5
string matrix_room
Definition: matrix.qh:6
#define NULL
Definition: post.qh:17
const float FILE_WRITE
Definition: csprogsdefs.qc:233
ERASEABLE void url_single_fopen(string url, int mode, url_ready_func rdy, entity pass)
Definition: urllib.qc:87
void MX_JLF_(entity fh, entity pass, int status)
Definition: matrix.qc:145
string autocvar_matrix_server
Definition: matrix.qh:3
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ MX_JLF_()

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

Definition at line 145 of file matrix.qc.

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

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

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 }
const float URL_READY_CANWRITE
Definition: urllib.qh:16
ERASEABLE void url_fputs(entity e, string s)
Definition: urllib.qc:312
ERASEABLE void url_fclose(entity e)
Definition: urllib.qc:207
#define pass(name, colormin, colormax)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ MX_Join()

void MX_Join ( string  room)

Definition at line 115 of file matrix.qc.

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

Referenced by GENERIC_COMMAND().

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),
120  FILE_WRITE,
121  MX_JLF_,
122  NULL
123  );
124 }
string matrix_access_token
Definition: matrix.qh:5
string matrix_room
Definition: matrix.qh:6
#define NULL
Definition: post.qh:17
const float FILE_WRITE
Definition: csprogsdefs.qc:233
ERASEABLE void url_single_fopen(string url, int mode, url_ready_func rdy, entity pass)
Definition: urllib.qc:87
void MX_JLF_(entity fh, entity pass, int status)
Definition: matrix.qc:145
string autocvar_matrix_server
Definition: matrix.qh:3
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ MX_Leave()

void MX_Leave ( string  room)

Definition at line 125 of file matrix.qc.

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

Referenced by GENERIC_COMMAND().

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),
130  FILE_WRITE,
131  MX_JLF_,
132  NULL
133  );
134 }
string matrix_access_token
Definition: matrix.qh:5
string matrix_room
Definition: matrix.qh:6
#define NULL
Definition: post.qh:17
const float FILE_WRITE
Definition: csprogsdefs.qc:233
ERASEABLE void url_single_fopen(string url, int mode, url_ready_func rdy, entity pass)
Definition: urllib.qc:87
void MX_JLF_(entity fh, entity pass, int status)
Definition: matrix.qc:145
string autocvar_matrix_server
Definition: matrix.qh:3
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ MX_Messages()

void MX_Messages ( string  from)

Definition at line 34 of file matrix.qc.

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_().

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,
40  FILE_READ,
42  NULL
43  );
44 }
string matrix_access_token
Definition: matrix.qh:5
const float FILE_READ
Definition: csprogsdefs.qc:231
string matrix_room
Definition: matrix.qh:6
#define NULL
Definition: post.qh:17
ERASEABLE void url_single_fopen(string url, int mode, url_ready_func rdy, entity pass)
Definition: urllib.qc:87
void MX_Messages_(entity fh, entity pass, int status)
Definition: matrix.qc:45
string autocvar_matrix_server
Definition: matrix.qh:3
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ MX_Messages_()

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

Definition at line 45 of file matrix.qc.

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

Referenced by MX_Messages(), and MX_Nick_().

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 }
const float URL_READY_CANREAD
Definition: urllib.qh:17
const float URL_READY_CLOSED
Definition: urllib.qh:15
ERASEABLE int json_parse(string in, bool() func)
Definition: json.qc:230
#define EXPECT_NE(val1, val2)
Definition: test.qh:52
#define LOG_WARNF(...)
Definition: log.qh:67
ERASEABLE string json_get(int buf, string key)
Definition: json.qc:276
spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 f1 s1 strcat(_("Level %s: "), "^BG%s\3\, _("^BGPress ^F2%s^BG to enter the game"))
ERASEABLE void url_fclose(entity e)
Definition: urllib.qc:207
void MX_Messages(string from)
Definition: matrix.qc:34
bool _json_parse_object()
parse a json object
Definition: json.qc:36
ERASEABLE string url_fgets(entity e)
Definition: urllib.qc:287
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ MX_Nick()

void MX_Nick ( string  name)

Definition at line 6 of file matrix.qc.

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().

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),
13  FILE_WRITE,
14  MX_Nick_,
15  pass
16  );
17 }
entity() spawn
string matrix_access_token
Definition: matrix.qh:5
string matrix_user
Definition: matrix.qh:4
const float FILE_WRITE
Definition: csprogsdefs.qc:233
ERASEABLE void url_single_fopen(string url, int mode, url_ready_func rdy, entity pass)
Definition: urllib.qc:87
#define new_pure(class)
purely logical entities (.origin doesn&#39;t work)
Definition: oo.qh:62
void MX_Nick_(entity fh, entity pass, int status)
Definition: matrix.qc:18
#define pass(name, colormin, colormax)
string autocvar_matrix_server
Definition: matrix.qh:3
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ MX_Nick_()

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

Definition at line 18 of file matrix.qc.

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

Referenced by MX_Nick().

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 }
const float URL_READY_CANWRITE
Definition: urllib.qh:16
ERASEABLE void url_fputs(entity e, string s)
Definition: urllib.qc:312
ERASEABLE void url_fclose(entity e)
Definition: urllib.qc:207
#define pass(name, colormin, colormax)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ MX_Say()

void MX_Say ( string  body)

Definition at line 187 of file matrix.qc.

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().

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),
195  FILE_WRITE,
196  MX_Say_,
197  pass
198  );
199 }
entity() spawn
string matrix_access_token
Definition: matrix.qh:5
string matrix_room
Definition: matrix.qh:6
const float FILE_WRITE
Definition: csprogsdefs.qc:233
ERASEABLE void url_single_fopen(string url, int mode, url_ready_func rdy, entity pass)
Definition: urllib.qc:87
#define new_pure(class)
purely logical entities (.origin doesn&#39;t work)
Definition: oo.qh:62
#define pass(name, colormin, colormax)
void MX_Say_(entity fh, entity pass, int status)
Definition: matrix.qc:200
string autocvar_matrix_server
Definition: matrix.qh:3
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ MX_Say_()

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

Definition at line 200 of file matrix.qc.

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

Referenced by MX_Say(), and MX_Typing_().

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 }
const float URL_READY_CANWRITE
Definition: urllib.qh:16
ERASEABLE void url_fputs(entity e, string s)
Definition: urllib.qc:312
ERASEABLE void url_fclose(entity e)
Definition: urllib.qc:207
#define strfree(this)
Definition: string.qh:56
#define pass(name, colormin, colormax)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ MX_Sync()

void MX_Sync ( string  since)

Definition at line 70 of file matrix.qc.

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_().

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
string matrix_access_token
Definition: matrix.qh:5
const float FILE_READ
Definition: csprogsdefs.qc:231
string matrix_room
Definition: matrix.qh:6
spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 f1 s1 strcat(_("Level %s: "), "^BG%s\3\, _("^BGPress ^F2%s^BG to enter the game"))
#define NULL
Definition: post.qh:17
ERASEABLE void url_single_fopen(string url, int mode, url_ready_func rdy, entity pass)
Definition: urllib.qc:87
string autocvar_matrix_server
Definition: matrix.qh:3
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ MX_Sync_()

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

Definition at line 89 of file matrix.qc.

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

Referenced by MX_Messages_(), and MX_Sync().

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 }
const float URL_READY_CANREAD
Definition: urllib.qh:17
const float URL_READY_CLOSED
Definition: urllib.qh:15
ERASEABLE int json_parse(string in, bool() func)
Definition: json.qc:230
#define EXPECT_NE(val1, val2)
Definition: test.qh:52
string matrix_room
Definition: matrix.qh:6
#define LOG_WARNF(...)
Definition: log.qh:67
ERASEABLE string json_get(int buf, string key)
Definition: json.qc:276
spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 f1 s1 strcat(_("Level %s: "), "^BG%s\3\, _("^BGPress ^F2%s^BG to enter the game"))
ERASEABLE void url_fclose(entity e)
Definition: urllib.qc:207
bool _json_parse_object()
parse a json object
Definition: json.qc:36
void MX_Sync(string since)
Definition: matrix.qc:70
ERASEABLE string url_fgets(entity e)
Definition: urllib.qc:287
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ MX_Typing()

void MX_Typing ( bool  state)

Definition at line 159 of file matrix.qc.

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

Referenced by GENERIC_COMMAND().

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),
166  FILE_WRITE,
167  MX_Typing_,
168  pass
169  );
170 }
float state
Definition: subs.qh:32
entity() spawn
string matrix_access_token
Definition: matrix.qh:5
string matrix_room
Definition: matrix.qh:6
string matrix_user
Definition: matrix.qh:4
void MX_Typing_(entity fh, entity pass, int status)
Definition: matrix.qc:171
const float FILE_WRITE
Definition: csprogsdefs.qc:233
ERASEABLE void url_single_fopen(string url, int mode, url_ready_func rdy, entity pass)
Definition: urllib.qc:87
#define new_pure(class)
purely logical entities (.origin doesn&#39;t work)
Definition: oo.qh:62
#define pass(name, colormin, colormax)
string autocvar_matrix_server
Definition: matrix.qh:3
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ MX_Typing_()

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

Definition at line 171 of file matrix.qc.

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

Referenced by MX_JLF_(), and MX_Typing().

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 }
const float URL_READY_CANWRITE
Definition: urllib.qh:16
ERASEABLE void url_fputs(entity e, string s)
Definition: urllib.qc:312
ERASEABLE void url_fclose(entity e)
Definition: urllib.qc:207
#define pass(name, colormin, colormax)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ message

string message

Definition at line 3 of file matrix.qc.