Skip to content

Commit

Permalink
Moved community host constant into a variable
Browse files Browse the repository at this point in the history
- Set the default community host to principia-web.se for now
- Need to add UI options for changing the host at runtime + browsing the
  old archive
  • Loading branch information
sdac committed Aug 8, 2022
1 parent 76e7ca4 commit 2f8f9cf
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 50 deletions.
2 changes: 1 addition & 1 deletion build-windows/go
Expand Up @@ -78,7 +78,7 @@ if [ "$release" -eq "1" ]; then
exit
fi

($skipmake || $makecmd CFLAGS="$DEBUGFLAGS_CC" CXXFLAGS="$DEBUGFLAGS_CXX") &&
($skipmake || $makecmd CFLAGS="$DEBUGFLAGS_CC" CXXFLAGS="$DEBUGFLAGS_CXX" -j9 ) &&
if [ "$run" -eq "1" ]; then
if [ "$debug" -eq "2" ]; then
drmemory -logdir ./drmemory -- principia
Expand Down
2 changes: 1 addition & 1 deletion src/src/game-gui.cc
Expand Up @@ -1444,7 +1444,7 @@ game::widget_clicked(principia_wdg *w, uint8_t button_id, int pid)
P.add_action(ACTION_AUTOSAVE, 0);
P.num_unread_messages = 0;
char tmp[256];
snprintf(tmp, 255, "http://" COMMUNITY_HOST "/user/%s", P.username);
snprintf(tmp, 255, "http://%s/user/%s", P.community_host, P.username);
ui::open_url(tmp);

snprintf(tmp, 255, "%s", P.username);
Expand Down
50 changes: 35 additions & 15 deletions src/src/main.cc
Expand Up @@ -1970,7 +1970,8 @@ _download_pkg(void *_p)
tms_debugf("save: %s", save_path);

char url[1024];
sprintf(url, "http://" COMMUNITY_HOST "/" COMMUNITY_SECRET "/xxxx.php?i=%d",
snprintf(url, 1023, "http://%s/" COMMUNITY_SECRET "/xxxx.php?i=%d",
P.community_host,
_play_pkg_id);
//tms_infof("url: %s", url);
long http_code = 0;
Expand Down Expand Up @@ -2110,7 +2111,8 @@ _download_level(void *p)


char url[1024];
sprintf(url, "http://" COMMUNITY_HOST "/" COMMUNITY_SECRET "/%s.php?i=%d&h=%u",
snprintf(url, 1023, "http://%s/" COMMUNITY_SECRET "/%s.php?i=%d&h=%u",
P.community_host,
_play_download_for_pkg ? "xxxxx" : (type == LEVEL_DB ? "x":(derive == true ? "xxx" : "xxxxxx")),
_play_id, r);
//tms_infof("url: %s", url);
Expand Down Expand Up @@ -2522,7 +2524,9 @@ _check_version_code(void *_unused)
if (P.curl) {
init_curl_defaults(P.curl);

curl_easy_setopt(P.curl, CURLOPT_URL, "http://" COMMUNITY_HOST "/principia-version-code");
char url[1024];
snprintf(url, 1023, "http://%s/principia-version-code", P.community_host);
curl_easy_setopt(P.curl, CURLOPT_URL, url);

curl_easy_setopt(P.curl, CURLOPT_WRITEFUNCTION, write_memory_cb);
curl_easy_setopt(P.curl, CURLOPT_WRITEDATA, (void*)&chunk);
Expand All @@ -2547,7 +2551,7 @@ _check_version_code(void *_unused)
#elif defined TMS_BACKEND_IOS
ui::message("A new version of Principia is available. Please visit the App Store to get the latest version.", true);
# else
ui::message("A new version of Principia is available. Please go to " COMMUNITY_HOST " to download the latest version.", true);
ui::message("A new version of Principia is available. Please go to www.principiagame.com/download to download the latest version.", true);
# endif
}

Expand Down Expand Up @@ -2625,9 +2629,9 @@ _get_featured_levels(void *_num)

char url[1024];
if (fl_fetch_time && file_exists(featured_data_path) && !ignore_fl_cache) {
snprintf(url, 1023, "http://" COMMUNITY_HOST "/" COMMUNITY_SECRET "/get_feature.php?num=%" PRIu32 "&time=%d", num_featured_levels, fl_fetch_time);
snprintf(url, 1023, "http://%s/" COMMUNITY_SECRET "/get_feature.php?num=%" PRIu32 "&time=%d", P.community_host, num_featured_levels, fl_fetch_time);
} else {
snprintf(url, 1023, "http://" COMMUNITY_HOST "/" COMMUNITY_SECRET "/get_feature.php?num=%" PRIu32, num_featured_levels);
snprintf(url, 1023, "http://%s/" COMMUNITY_SECRET "/get_feature.php?num=%" PRIu32, P.community_host, num_featured_levels);
}

curl_easy_setopt(P.curl, CURLOPT_URL, url);
Expand Down Expand Up @@ -2968,7 +2972,9 @@ _publish_pkg(void *_unused)
if (P.curl) {
init_curl_defaults(P.curl);

curl_easy_setopt(P.curl, CURLOPT_URL, "http://" COMMUNITY_HOST "/" COMMUNITY_SECRET "/upload_package.php");
char url[1024];
snprintf(url, 1023, "http://%s/" COMMUNITY_SECRET "/upload_package.php", P.community_host);
curl_easy_setopt(P.curl, CURLOPT_URL, url);

curl_easy_setopt(P.curl, CURLOPT_HTTPPOST, formpost);

Expand Down Expand Up @@ -3110,7 +3116,9 @@ _publish_level(void *p)
if (P.curl) {
init_curl_defaults(P.curl);

curl_easy_setopt(P.curl, CURLOPT_URL, "http://" COMMUNITY_HOST "/upload.php");
char url[1024];
snprintf(url, 1023, "http://%s/upload.php", P.community_host);
curl_easy_setopt(P.curl, CURLOPT_URL, url);

curl_easy_setopt(P.curl, CURLOPT_HTTPPOST, formpost);

Expand Down Expand Up @@ -3300,7 +3308,9 @@ _submit_score(void *p)
struct header_data hd = {0};
init_curl_defaults(P.curl);

curl_easy_setopt(P.curl, CURLOPT_URL, "http://" COMMUNITY_HOST "/" COMMUNITY_SECRET "/submit_score.php");
char url[1024];
snprintf(url, 1023, "http://%s/" COMMUNITY_SECRET "/submit_score.php", P.community_host);
curl_easy_setopt(P.curl, CURLOPT_URL, url);

curl_easy_setopt(P.curl, CURLOPT_WRITEHEADER, &hd);

Expand Down Expand Up @@ -3383,7 +3393,9 @@ _ping(void *p)
if (P.curl) {
init_curl_defaults(P.curl);

curl_easy_setopt(P.curl, CURLOPT_URL, "http://" COMMUNITY_HOST "/ping.php");
char url[1024];
snprintf(url, 1023, "http://%s/ping.php", P.community_host);
curl_easy_setopt(P.curl, CURLOPT_URL, url);

curl_easy_setopt(P.curl, CURLOPT_WRITEFUNCTION, write_memory_cb);
curl_easy_setopt(P.curl, CURLOPT_WRITEDATA, (void*)&chunk);
Expand Down Expand Up @@ -3457,7 +3469,9 @@ _login(void *p)
if (P.curl) {
init_curl_defaults(P.curl);

curl_easy_setopt(P.curl, CURLOPT_URL, "http://" COMMUNITY_HOST "/" COMMUNITY_SECRET "/xx.php");
char url[1024];
snprintf(url, 1023, "http://%s/" COMMUNITY_SECRET "/xx.php", P.community_host);
curl_easy_setopt(P.curl, CURLOPT_URL, url);

curl_easy_setopt(P.curl, CURLOPT_HTTPPOST, formpost);

Expand Down Expand Up @@ -3573,8 +3587,9 @@ _register(void *p)

if (P.curl) {
init_curl_defaults(P.curl);

curl_easy_setopt(P.curl, CURLOPT_URL, "http://" COMMUNITY_HOST "/" COMMUNITY_SECRET "/" REGISTER_ANDROID_FILE ".php");
char url[1024];
snprintf(url, 1023, "http://%s/" COMMUNITY_SECRET "/" REGISTER_ANDROID_FILE ".php", P.community_host);
curl_easy_setopt(P.curl, CURLOPT_URL, url);

curl_easy_setopt(P.curl, CURLOPT_HTTPPOST, formpost);

Expand Down Expand Up @@ -3711,7 +3726,9 @@ _link_account(void *p)
if (P.curl) {
init_curl_defaults(P.curl);

curl_easy_setopt(P.curl, CURLOPT_URL, "http://" COMMUNITY_HOST "/" COMMUNITY_SECRET "/" LINK_ACCOUNT_FILE ".php");
char url[1024];
snprintf(url, 1023, "http://%s/" COMMUNITY_SECRET "/" LINK_ACCOUNT_FILE ".php", P.community_host);
curl_easy_setopt(P.curl, CURLOPT_URL, url);

curl_easy_setopt(P.curl, CURLOPT_HTTPPOST, formpost);

Expand Down Expand Up @@ -4039,6 +4056,7 @@ initial_loader(int step)
switch (step) {
case 0:
{
P.community_host = "principia-web.se";
static const char *u_dirs[]={
"/lvl", "/lvl/local",
"/pkg", "/pkg/local",
Expand Down Expand Up @@ -4381,7 +4399,9 @@ P_get_cookie_data(char **u, char **k, char **sid, char **l)
if (P.curl) {
init_curl_defaults(P.curl);

curl_easy_setopt(P.curl, CURLOPT_URL, "http://" COMMUNITY_HOST "/" COMMUNITY_SECRET "/xx.php");
char url[1024];
snprintf(url, 1023, "http://%s/" COMMUNITY_SECRET "/xx.php", P.community_host);
curl_easy_setopt(P.curl, CURLOPT_URL, url);

struct curl_slist *cookies;
CURLcode res = curl_easy_getinfo(P.curl, CURLINFO_COOKIELIST, &cookies);
Expand Down
18 changes: 2 additions & 16 deletions src/src/main.hh
Expand Up @@ -25,28 +25,15 @@ class pkginfo;
#define STR1(x) #x
#define STR(x) STR1(x)

#if defined(DEBUG)
# ifdef PAJLADA
//# define COMMUNITY_HOST "pajlada.se"
# define COMMUNITY_HOST "principiagame.com"
# else
# define COMMUNITY_HOST "principiagame.com"
# endif
#else
# define COMMUNITY_HOST "principiagame.com"
#endif
#define UPDATE_URL "http://www.principiagame.com/download"

#if defined(TMS_BACKEND_WINDOWS)
#define OS_STRING "Windows"
#define UPDATE_URL "http://" COMMUNITY_HOST "/download"
#elif defined(TMS_BACKEND_LINUX_SS)
#define OS_STRING "Linux_SS"
#define UPDATE_URL "http://" COMMUNITY_HOST "/download"
#elif defined(TMS_BACKEND_LINUX)
#define OS_STRING "Linux"
#define UPDATE_URL "http://" COMMUNITY_HOST "/download"
#elif defined(TMS_BACKEND_ANDROID)
#define UPDATE_URL "http://play.google.com/store/apps/details?id=com.bithack.principia"
# if defined(TMS_BACKEND_ANDROID_X86)
# define OS_STRING "Android x86"
# elif defined(TMS_BACKEND_ANDROID_ARMEABI)
Expand All @@ -57,11 +44,9 @@ class pkginfo;
# define OS_STRING "Android"
# endif
#elif defined(TMS_BACKEND_IOS)
#define UPDATE_URL "http://" COMMUNITY_HOST "/download?appstore"
#define OS_STRING "iOS"
#else
#define OS_STRING "unknown"
#define UPDATE_URL "http://" COMMUNITY_HOST "/download"
#endif

#if defined(TMS_BACKEND_ANDROID) || defined(TMS_BACKEND_IOS)
Expand Down Expand Up @@ -280,6 +265,7 @@ extern class principia
int focused;
bool loaded;

const char *community_host;
char *username;
int user_id;
int num_unread_messages;
Expand Down
18 changes: 11 additions & 7 deletions src/src/menu-base.cc
Expand Up @@ -32,8 +32,8 @@ menu_base::widget_clicked(principia_wdg *w, uint8_t button_id, int pid)
pscreen::refresh_username();
P.add_action(ACTION_REFRESH_WIDGETS, 0);

char tmp[256];
snprintf(tmp, 255, "http://" COMMUNITY_HOST "/user/%s", P.username);
char tmp[1024];
snprintf(tmp, 1023, "http://%s/user/%s", P.community_host, P.username);
ui::open_url(tmp);
} else {
ui::open_dialog(DIALOG_LOGIN);
Expand All @@ -42,7 +42,11 @@ menu_base::widget_clicked(principia_wdg *w, uint8_t button_id, int pid)
break;

case BTN_MESSAGE:
ui::open_url("http://" COMMUNITY_HOST "/version-redir.php");
{
char url[1024];
snprintf(url, 1023, "http://%s/version-redir.php", P.community_host);
ui::open_url(url);
}
break;

case BTN_BITHACK:
Expand All @@ -56,17 +60,17 @@ menu_base::widget_clicked(principia_wdg *w, uint8_t button_id, int pid)
case BTN_ENTITY:
{
uint32_t id = VOID_TO_UINT32(w->data3);
char tmp[512];
snprintf(tmp, 511, "http://" COMMUNITY_HOST "/level/%" PRIu32, id);
char tmp[1024];
snprintf(tmp, 1023, "http://%s/level/%" PRIu32, P.community_host, id);
ui::open_url(tmp);
}
break;

case BTN_CONTEST:
{
uint32_t id = VOID_TO_UINT32(w->data3);
char tmp[512];
snprintf(tmp, 511, "http://" COMMUNITY_HOST "/contest/%" PRIu32, id);
char tmp[1024];
snprintf(tmp, 1023, "http://%s/contest/%" PRIu32, P.community_host, id);
ui::open_url(tmp);
}
break;
Expand Down
6 changes: 3 additions & 3 deletions src/src/menu_main.cc
Expand Up @@ -25,7 +25,7 @@ menu_main::widget_clicked(principia_wdg *w, uint8_t button_id, int pid)
switch (button_id) {
case BTN_SHITTY:
{
ui::open_url("http://wiki." COMMUNITY_HOST "/wiki/Bad_Graphics");
ui::open_url("http://wiki.principiagame.com/wiki/Bad_Graphics");
}
break;

Expand Down Expand Up @@ -56,7 +56,7 @@ menu_main::widget_clicked(principia_wdg *w, uint8_t button_id, int pid)
ui::open_url(0);
#else
char tmp[512];
sprintf(tmp, "http://%s/", COMMUNITY_HOST);
snprintf(tmp, 511, "http://%s/", P.community_host);
ui::open_url(tmp);
#endif
}
Expand Down Expand Up @@ -226,7 +226,7 @@ menu_main::handle_input(tms::event *ev, int action)
return T_OK;

case TMS_KEY_V:
tms_debugf("Community host: %s. Update URL: %s", COMMUNITY_HOST, UPDATE_URL);
tms_debugf("Community host: %s. Update URL: %s", P.community_host, UPDATE_URL);
return T_OK;

case TMS_KEY_O:
Expand Down
16 changes: 9 additions & 7 deletions src/src/ui.cc
Expand Up @@ -583,7 +583,7 @@ void
ui_cb_back_to_community(void)
{
char tmp[1024];
snprintf(tmp, 1023, "http://" COMMUNITY_HOST "/level/%d", W->level.community_id);
snprintf(tmp, 1023, "http://%s/level/%d", P.community_host, W->level.community_id);

ui::open_url(tmp);
}
Expand Down Expand Up @@ -936,7 +936,7 @@ extern "C" jstring
Java_org_libsdl_app_PrincipiaBackend_getLevelPage(JNIEnv *env, jclass jcls)
{
char tmp[1024];
snprintf(tmp, 1023, "http://" COMMUNITY_HOST "/level/%d", W->level.community_id);
snprintf(tmp, 1023, "http://%s/level/%d", P.community_host, W->level.community_id);

return env->NewStringUTF(tmp);
}
Expand Down Expand Up @@ -1770,8 +1770,8 @@ Java_org_libsdl_app_PrincipiaBackend_setConsumableType(JNIEnv *env, jclass _jcls
extern "C" jstring
Java_org_libsdl_app_PrincipiaBackend_getCurrentCommunityUrl(JNIEnv *env, jclass _jcls)
{
char tmp[256];
snprintf(tmp, 255, "http://" COMMUNITY_HOST "/level/%d", W->level.community_id);
char tmp[1024];
snprintf(tmp, 1023, "http://%s/level/%d", P.community_host, W->level.community_id);

return env->NewStringUTF(tmp);
}
Expand Down Expand Up @@ -9105,7 +9105,9 @@ on_login_btn_click(GtkWidget *w, GdkEventButton *ev, gpointer user_data)
gtk_label_set_text(login_status, "Enter data into both fields.");
}
} else if (btn_pressed(w, login_btn_forgot_password, user_data)) {
ui::open_url("http://" COMMUNITY_HOST "/forgot_password.php");
char url[1024];
snprintf(url, 1023, "http://%s/forgot_password.php", P.community_host);
ui::open_url(url);
}

return false;
Expand Down Expand Up @@ -13533,7 +13535,7 @@ _open_tips_dialog(gpointer unused)
}

if (result == GTK_RESPONSE_YES)
ui::open_url("http://" COMMUNITY_HOST "/gettingstarted.php");
ui::open_url("http://wiki.principiagame.com/");

break;
} while (true);
Expand Down Expand Up @@ -13738,7 +13740,7 @@ _open_published(gpointer unused)
case GTK_RESPONSE_ACCEPT:
{
char tmp[1024];
snprintf(tmp, 1023, "http://" COMMUNITY_HOST "/level/%d", W->level.community_id);
snprintf(tmp, 1023, "http://%s/level/%d", P.community_host, W->level.community_id);

ui::open_url(tmp);
}
Expand Down

0 comments on commit 2f8f9cf

Please sign in to comment.