Skip to content

Instantly share code, notes, and snippets.

@asarium
Created May 31, 2015 14:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save asarium/ff6da96d1060cce26d17 to your computer and use it in GitHub Desktop.
Save asarium/ff6da96d1060cce26d17 to your computer and use it in GitHub Desktop.
From c449900b08e1a06954d0120690bb3d0859ddedf6 Mon Sep 17 00:00:00 2001
From: asarium <asarium@gmail.com>
Date: Sun, 31 May 2015 16:10:09 +0200
Subject: [PATCH] Fix memory leak
---
code/network/stand_gui-unix.cpp | 1 +
1 file changed, 1 insertion(+)
diff --git a/code/network/stand_gui-unix.cpp b/code/network/stand_gui-unix.cpp
index 715f17b..fcd8fda 100644
--- a/code/network/stand_gui-unix.cpp
+++ b/code/network/stand_gui-unix.cpp
@@ -324,6 +324,7 @@ void webapiExecuteCommands() {
for (SCP_vector<WebapiCommand*>::iterator iter = webapiCommandQueue.begin(); iter != webapiCommandQueue.end();
++iter) {
(*iter)->execute();
+ delete *iter;
}
webapiCommandQueue.clear();
--
1.9.5.msysgit.0
From aad334e2447cdb48afba15fd10daae74e27af219 Mon Sep 17 00:00:00 2001
From: asarium <asarium@gmail.com>
Date: Sun, 31 May 2015 16:09:12 +0200
Subject: [PATCH] Fix server not shutting down
---
code/network/stand_gui-unix.cpp | 90 +++++++++++++++++++++++++++++++----------
1 file changed, 69 insertions(+), 21 deletions(-)
diff --git a/code/network/stand_gui-unix.cpp b/code/network/stand_gui-unix.cpp
index 78958dc..715f17b 100644
--- a/code/network/stand_gui-unix.cpp
+++ b/code/network/stand_gui-unix.cpp
@@ -201,6 +201,57 @@ public:
virtual void execute() = 0;
};
+class ChangeServerInformationCommand : public WebapiCommand
+{
+ SCP_string name;
+ bool hasName;
+
+ SCP_string passwd;
+ bool hasPasswd;
+
+ int framecap;
+
+public:
+ ChangeServerInformationCommand() : hasName(false), hasPasswd(false), framecap(0) {}
+
+ void setFrameCap(int cap) { framecap = cap; }
+
+ void setName(const char* newName)
+ {
+ hasName = true;
+ name.assign(newName);
+ }
+
+ void setPasswd(const char* newPasswd)
+ {
+ hasPasswd = true;
+ passwd.assign(newPasswd);
+ }
+
+ virtual void execute()
+ {
+ if (hasName) {
+ strcpy_s(Netgame.name, name.c_str());
+ strcpy_s(Multi_options_g.std_pname, name.c_str());
+ // update fs2netd with the info
+ if (MULTI_IS_TRACKER_GAME) {
+ fs2netd_gameserver_disconnect();
+ Sleep(50);
+ fs2netd_gameserver_start();
+ }
+ }
+
+ if (hasPasswd) {
+ strcpy_s(Multi_options_g.std_passwd, passwd.c_str());
+ }
+
+ if (framecap)
+ {
+ Multi_options_g.std_framecap = framecap;
+ }
+ }
+};
+
class KickPlayerCommand: public WebapiCommand {
public:
KickPlayerCommand(int playerId)
@@ -404,28 +455,25 @@ json_t* serverGet(ResourceContext *context) {
}
json_t* serverPut(ResourceContext *context) {
- const char* name = json_string_value(json_object_get(context->requestEntity, "name"));
- if (name) {
- strcpy_s(Netgame.name, name);
- strcpy_s(Multi_options_g.std_pname, name);
- // update fs2netd with the info
- if (MULTI_IS_TRACKER_GAME) {
- fs2netd_gameserver_disconnect();
- Sleep(50);
- fs2netd_gameserver_start();
- }
- }
- const char* passwd = json_string_value(json_object_get(context->requestEntity, "password"));
- if (passwd) {
- strcpy_s(Multi_options_g.std_passwd, passwd);
- }
- int framecap = atoi(json_string_value(json_object_get(context->requestEntity, "framecap")));
- if (framecap)
- {
- Multi_options_g.std_framecap = framecap;
- }
+ ChangeServerInformationCommand* changeCommand = new ChangeServerInformationCommand();
- return json_object();
+ const char* name = json_string_value(json_object_get(context->requestEntity, "name"));
+ if (name) {
+ changeCommand->setName(name);
+ }
+ const char* passwd = json_string_value(json_object_get(context->requestEntity, "password"));
+ if (passwd) {
+ changeCommand->setPasswd(passwd);
+ }
+ int framecap = atoi(json_string_value(json_object_get(context->requestEntity, "framecap")));
+ if (framecap)
+ {
+ changeCommand->setFrameCap(framecap);
+ }
+
+ webapiAddCommand(changeCommand);
+
+ return json_object();
}
json_t* serverDelete(ResourceContext *context) {
--
1.9.5.msysgit.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment