diff --git a/config.ini b/config.ini index f6ac838..732d305 100644 --- a/config.ini +++ b/config.ini @@ -17,6 +17,8 @@ acceptallcustomnames=true # should attempts to log into non-existent accounts # automatically create them? autocreateaccounts=true +# support logging in with auth cookies? +useauthcookies=false # how often should everything be flushed to the database? # the default is 4 minutes dbsaveinterval=240 diff --git a/src/servers/CNLoginServer.cpp b/src/servers/CNLoginServer.cpp index 9e905e6..95d41d1 100644 --- a/src/servers/CNLoginServer.cpp +++ b/src/servers/CNLoginServer.cpp @@ -112,6 +112,10 @@ void CNLoginServer::login(CNSocket* sock, CNPacketData* data) { if (isCookieAuth) { // username encoded in TEGid raw userLogin = std::string((char*)login->szCookie_TEGid); + + // clients that use web login but without proper cookies + // send their passwords instead, so store that + userPassword = std::string((char*)login->szCookie_authid); } else { /* * The std::string -> char* -> std::string maneuver should remove any @@ -121,6 +125,11 @@ void CNLoginServer::login(CNSocket* sock, CNPacketData* data) { userPassword = std::string(AUTOU16TOU8(login->szPassword).c_str()); } + if (!settings::USEAUTHCOOKIES) { + // use normal login flow + isCookieAuth = false; + } + // check username regex if (!CNLoginServer::isUsernameGood(userLogin)) { // send a custom error message diff --git a/src/settings.cpp b/src/settings.cpp index 5949f52..85554ea 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -13,6 +13,7 @@ bool settings::SANDBOX = true; int settings::LOGINPORT = 23000; bool settings::APPROVEALLNAMES = true; bool settings::AUTOCREATEACCOUNTS = true; +bool settings::USEAUTHCOOKIES = false; int settings::DBSAVEINTERVAL = 240; int settings::SHARDPORT = 23001; @@ -87,6 +88,7 @@ void settings::init() { LOGINPORT = reader.GetInteger("login", "port", LOGINPORT); APPROVEALLNAMES = reader.GetBoolean("login", "acceptallcustomnames", APPROVEALLNAMES); AUTOCREATEACCOUNTS = reader.GetBoolean("login", "autocreateaccounts", AUTOCREATEACCOUNTS); + USEAUTHCOOKIES = reader.GetBoolean("login", "useauthcookies", USEAUTHCOOKIES); DBSAVEINTERVAL = reader.GetInteger("login", "dbsaveinterval", DBSAVEINTERVAL); SHARDPORT = reader.GetInteger("shard", "port", SHARDPORT); SHARDSERVERIP = reader.Get("shard", "ip", SHARDSERVERIP); diff --git a/src/settings.hpp b/src/settings.hpp index 85fad68..a27eada 100644 --- a/src/settings.hpp +++ b/src/settings.hpp @@ -8,6 +8,7 @@ namespace settings { extern int LOGINPORT; extern bool APPROVEALLNAMES; extern bool AUTOCREATEACCOUNTS; + extern bool USEAUTHCOOKIES; extern int DBSAVEINTERVAL; extern int SHARDPORT; extern std::string SHARDSERVERIP;