From: TimePath Date: Wed, 26 Aug 2015 01:06:56 +0000 (+1000) Subject: Basic message passing X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=d218bc1ec1b2a521fe1f8e20f730d533eda3294c;p=xonotic%2Fxonotic-data.pk3dir.git Basic message passing --- diff --git a/qcsrc/common/mutators/all.inc b/qcsrc/common/mutators/all.inc index 0471dff7c..a874e9810 100644 --- a/qcsrc/common/mutators/all.inc +++ b/qcsrc/common/mutators/all.inc @@ -1,3 +1,4 @@ #include "mutator/damagetext.qc" #include "mutator/itemstime.qc" +#include "mutator/social.qc" #include "mutator/waypointsprites.qc" diff --git a/qcsrc/common/mutators/mutator/social.qc b/qcsrc/common/mutators/mutator/social.qc new file mode 100644 index 000000000..7ee332d26 --- /dev/null +++ b/qcsrc/common/mutators/mutator/social.qc @@ -0,0 +1,76 @@ +#ifdef MENUQC +REGISTER_MUTATOR(social, true); + +void Social_parse(entity fh, entity pass, int status) +{ + switch (status) { + case URL_READY_CANWRITE: { + string msg = pass.message; + url_fputs(fh, msg); + url_fputs(fh, "\n"); + url_fclose(fh); + break; + } + case URL_READY_CANREAD: { + string first = url_fgets(fh); + if (first == "") return; + int id = stoi(first); + printf("from player %d:\n", id); + for (string input; (input = url_fgets(fh)); ) { + print(input, "\n"); + } + url_fclose(fh); + break; + } + case URL_READY_CLOSED: break; + case URL_READY_ERROR: + default: + { + printf("Social_parse(): %s\n", ftos(status)); + break; + } + } +} + +string autocvar_g_social_uri = "http://localhost:5000"; + +void Social_send(int to, string msg) +{ + entity e = spawn(); e.message = msg; + if (crypto_getmyidstatus(0) > 0) { + url_single_fopen( + sprintf("%s/send?to=%d", autocvar_g_social_uri, to), + FILE_APPEND, + Social_parse, + e + ); + } +} + +void Social_recv() +{ + if (crypto_getmyidstatus(0) > 0) { + url_single_fopen( + sprintf("%s/recv", autocvar_g_social_uri), + FILE_APPEND, + Social_parse, + NULL + ); + } +} + +MUTATOR_HOOKFUNCTION(social, GameCommand) { + if (MUTATOR_RETURNVALUE) return false; // command was already handled + if (cmd_name == "ssend" && cmd_argc >= 3) { + int to = stoi(argv(1)); + string msg = substring(cmd_string, argv_start_index(2), argv_end_index(-1) - argv_start_index(2)); + Social_send(to, msg); + return true; + } + if (cmd_name == "srecv") { + Social_recv(); + return true; + } + return false; +} +#endif