ref: 0446a1adad55886093c25bcdf714fd339c5ddcc9
parent: 78a0de9cb560d3b4066913119e9597c57d558484
parent: 52d99f42430a2c3faec4ac0bb824a691605b98f7
author: Jonathan Dowland <jon+github@alcopop.org>
date: Thu Feb 28 22:15:51 EST 2019
Merge pull request #1142 from jmtd/petname Generate a random "pet" player username
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -75,6 +75,7 @@
net_io.c net_io.h
net_loop.c net_loop.h
net_packet.c net_packet.h
+ net_petname.c net_petname.h
net_query.c net_query.h
net_sdl.c net_sdl.h
net_server.c net_server.h
@@ -192,6 +193,7 @@
m_controls.c m_controls.h
net_io.c net_io.h
net_packet.c net_packet.h
+ net_petname.c net_petname.h
net_sdl.c net_sdl.h
net_query.c net_query.h
net_structrw.c net_structrw.h
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -94,6 +94,7 @@
net_io.c net_io.h \
net_loop.c net_loop.h \
net_packet.c net_packet.h \
+net_petname.c net_petname.h \
net_query.c net_query.h \
net_sdl.c net_sdl.h \
net_server.c net_server.h \
@@ -195,6 +196,7 @@
m_controls.c m_controls.h \
net_io.c net_io.h \
net_packet.c net_packet.h \
+net_petname.c net_petname.h \
net_sdl.c net_sdl.h \
net_query.c net_query.h \
net_structrw.c net_structrw.h \
--- a/src/net_client.c
+++ b/src/net_client.c
@@ -38,6 +38,7 @@
#include "net_query.h"
#include "net_server.h"
#include "net_structrw.h"
+#include "net_petname.h"
#include "w_checksum.h"
#include "w_wad.h"
@@ -1211,23 +1212,10 @@
// Try to set from the USER and USERNAME environment variables
// Otherwise, fallback to "Player"
- if (net_player_name == NULL)
- net_player_name = getenv("USER");
if (net_player_name == NULL)
- net_player_name = getenv("USERNAME");
-
- // On Windows, environment variables are in OEM codepage
- // encoding, so convert to UTF8:
-
-#ifdef _WIN32
- if (net_player_name != NULL)
{
- net_player_name = M_OEMToUTF8(net_player_name);
+ net_player_name = NET_GetRandomPetName();
}
-#endif
-
- if (net_player_name == NULL)
- net_player_name = "Player";
}
void NET_Init(void)
--- /dev/null
+++ b/src/net_petname.c
@@ -1,0 +1,118 @@
+//
+// Copyright(C) 2019 Jonathan Dowland
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License
+// as published by the Free Software Foundation; either version 2
+// of the License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// DESCRIPTION:
+// Generate a randomized, private, memorable name for a Player
+//
+
+#include <stdlib.h>
+#include <time.h>
+#include "doomtype.h"
+#include "m_misc.h"
+
+static const char * const adjectives [] = {
+ "Grumpy",
+ "Ecstatic",
+ "Surly",
+ "Prepared",
+ "Crafty",
+ "Alert",
+ "Sluggish",
+ "Testy",
+ "Reluctant",
+ "Languid",
+ "Passive",
+ "Pacifist",
+ "Aggressive",
+ "Hostile",
+ "Bubbly",
+ "Giggly",
+ "Laughing",
+ "Crying",
+ "Frowning",
+ "Torpid",
+ "Lethargic",
+ "Manic",
+ "Patient",
+ "Protective",
+ "Philosophical",
+ "Enquiring",
+ "Debating",
+ "Furious",
+ "Laid-Back",
+ "Easy-Going",
+ "Cromulent",
+ "Excitable",
+ "Tired",
+ "Exhausted",
+ "Ruminating",
+ "Redundant",
+ "Sporty",
+ "Ginger",
+ "Scary",
+ "Posh",
+ "Baby",
+};
+
+static const char * const nouns[] = {
+ "Frad",
+ // Doom
+ "Cacodemon",
+ "Arch-Vile",
+ "Cyberdemon",
+ "Imp",
+ "Demon",
+ "Mancubus",
+ "Arachnotron",
+ "Baron",
+ "Knight",
+ "Revenant",
+ // Hexen
+ "Ettin",
+ "Maulotaur",
+ "Centaur",
+ "Afrit",
+ "Serpent",
+ // Heretic
+ "Disciple",
+ "Gargoyle",
+ "Golem",
+ "Lich",
+ // Strife
+ "Sentinel",
+ "Acolyte",
+ "Templar",
+ "Reaver",
+ "Spectre",
+};
+
+/*
+ * ideally we would export this and the caller would invoke it during
+ * their setup routine. But, the two callers only invoke getRandomPetName
+ * once, so the initialization might as well occur then.
+ */
+static void InitPetName()
+{
+ srand((unsigned int)time(NULL));
+}
+
+char *NET_GetRandomPetName()
+{
+ const char *a, *n;
+
+ InitPetName();
+ a = adjectives[rand() % arrlen(adjectives)];
+ n = nouns[rand() % arrlen(nouns)];
+
+ return M_StringJoin(a, " ", n, NULL);
+}
--- /dev/null
+++ b/src/net_petname.h
@@ -1,0 +1,18 @@
+//
+// Copyright(C) 2019 Jonathan Dowland
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License
+// as published by the Free Software Foundation; either version 2
+// of the License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// DESCRIPTION:
+// Generate a randomized, private, memorable name for a Player
+//
+
+char *NET_GetRandomPetName();
--- a/src/setup/multiplayer.c
+++ b/src/setup/multiplayer.c
@@ -33,6 +33,8 @@
#include "net_io.h"
#include "net_query.h"
+#include "net_petname.h"
+
#define MULTI_START_HELP_URL "https://www.chocolate-doom.org/setup-multi-start"
#define MULTI_JOIN_HELP_URL "https://www.chocolate-doom.org/setup-multi-join"
#define MULTI_CONFIG_HELP_URL "https://www.chocolate-doom.org/setup-multi-config"
@@ -1096,29 +1098,8 @@
{
if (net_player_name == NULL)
{
- net_player_name = getenv("USER");
+ net_player_name = NET_GetRandomPetName();
}
-
- if (net_player_name == NULL)
- {
- net_player_name = getenv("USERNAME");
- }
-
- if (net_player_name == NULL)
- {
- net_player_name = "player";
- }
-
- // Now strdup() the string so that it's in a mutable form
- // that can be freed when the value changes.
-
-#ifdef _WIN32
- // On Windows, environment variables are in OEM codepage
- // encoding, so convert to UTF8:
- net_player_name = M_OEMToUTF8(net_player_name);
-#else
- net_player_name = M_StringDuplicate(net_player_name);
-#endif
}
void MultiplayerConfig(TXT_UNCAST_ARG(widget), void *user_data)