mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-14 10:05:44 -04:00
Minor code cleanup of LWeb
This commit is contained in:
parent
02f65b1c5d
commit
0540472b2f
@ -681,7 +681,7 @@ static void MainScreen_Login(void* w, int x, int y) {
|
||||
LWidget_Redraw(&s->lblStatus); return;
|
||||
}
|
||||
|
||||
if (GetTokenTask.Base.Working) return;
|
||||
if (GetTokenTask.Base.working) return;
|
||||
Options_Set("launcher-cc-username", user);
|
||||
Options_SetSecure("launcher-cc-password", pass, user);
|
||||
|
||||
@ -822,12 +822,12 @@ static void MainScreen_TickCheckUpdates(struct MainScreen* s) {
|
||||
static const String currentStr = String_FromConst(GAME_APP_VER);
|
||||
cc_uint32 latest, current;
|
||||
|
||||
if (!CheckUpdateTask.Base.Working) return;
|
||||
if (!CheckUpdateTask.Base.working) return;
|
||||
LWebTask_Tick(&CheckUpdateTask.Base);
|
||||
if (!CheckUpdateTask.Base.Completed) return;
|
||||
if (!CheckUpdateTask.Base.completed) return;
|
||||
|
||||
if (CheckUpdateTask.Base.Success) {
|
||||
latest = MainScreen_GetVersion(&CheckUpdateTask.LatestRelease);
|
||||
if (CheckUpdateTask.Base.success) {
|
||||
latest = MainScreen_GetVersion(&CheckUpdateTask.latestRelease);
|
||||
current = MainScreen_GetVersion(¤tStr);
|
||||
LLabel_SetConst(&s->lblUpdate, latest > current ? "&aNew release" : "&eUp to date");
|
||||
} else {
|
||||
@ -837,11 +837,11 @@ static void MainScreen_TickCheckUpdates(struct MainScreen* s) {
|
||||
}
|
||||
|
||||
static void MainScreen_TickGetToken(struct MainScreen* s) {
|
||||
if (!GetTokenTask.Base.Working) return;
|
||||
if (!GetTokenTask.Base.working) return;
|
||||
LWebTask_Tick(&GetTokenTask.Base);
|
||||
if (!GetTokenTask.Base.Completed) return;
|
||||
if (!GetTokenTask.Base.completed) return;
|
||||
|
||||
if (GetTokenTask.Base.Success) {
|
||||
if (GetTokenTask.Base.success) {
|
||||
SignInTask_Run(&s->iptUsername.text, &s->iptPassword.text);
|
||||
} else {
|
||||
MainScreen_Error(&GetTokenTask.Base, "signing in");
|
||||
@ -849,17 +849,17 @@ static void MainScreen_TickGetToken(struct MainScreen* s) {
|
||||
}
|
||||
|
||||
static void MainScreen_TickSignIn(struct MainScreen* s) {
|
||||
if (!SignInTask.Base.Working) return;
|
||||
if (!SignInTask.Base.working) return;
|
||||
LWebTask_Tick(&SignInTask.Base);
|
||||
if (!SignInTask.Base.Completed) return;
|
||||
if (!SignInTask.Base.completed) return;
|
||||
|
||||
if (SignInTask.Error) {
|
||||
LLabel_SetConst(&s->lblStatus, SignInTask.Error);
|
||||
if (SignInTask.error) {
|
||||
LLabel_SetConst(&s->lblStatus, SignInTask.error);
|
||||
LWidget_Redraw(&s->lblStatus);
|
||||
} else if (SignInTask.Base.Success) {
|
||||
} else if (SignInTask.Base.success) {
|
||||
/* website returns case correct username */
|
||||
if (!String_Equals(&s->iptUsername.text, &SignInTask.Username)) {
|
||||
LInput_SetText(&s->iptUsername, &SignInTask.Username);
|
||||
if (!String_Equals(&s->iptUsername.text, &SignInTask.username)) {
|
||||
LInput_SetText(&s->iptUsername, &SignInTask.username);
|
||||
LWidget_Redraw(&s->iptUsername);
|
||||
}
|
||||
|
||||
@ -872,11 +872,11 @@ static void MainScreen_TickSignIn(struct MainScreen* s) {
|
||||
}
|
||||
|
||||
static void MainScreen_TickFetchServers(struct MainScreen* s) {
|
||||
if (!FetchServersTask.Base.Working) return;
|
||||
if (!FetchServersTask.Base.working) return;
|
||||
LWebTask_Tick(&FetchServersTask.Base);
|
||||
if (!FetchServersTask.Base.Completed) return;
|
||||
if (!FetchServersTask.Base.completed) return;
|
||||
|
||||
if (FetchServersTask.Base.Success) {
|
||||
if (FetchServersTask.Base.success) {
|
||||
s->signingIn = false;
|
||||
if (Game_Hash.length) {
|
||||
Launcher_ConnectToServer(&Game_Hash);
|
||||
@ -1123,7 +1123,7 @@ static void ServersScreen_Connect(void* w, int x, int y) {
|
||||
|
||||
static void ServersScreen_Refresh(void* w, int x, int y) {
|
||||
struct LButton* btn;
|
||||
if (FetchServersTask.Base.Working) return;
|
||||
if (FetchServersTask.Base.working) return;
|
||||
|
||||
FetchServersTask_Run();
|
||||
btn = &ServersScreen_Instance.btnRefresh;
|
||||
@ -1167,8 +1167,8 @@ static void ServersScreen_ReloadServers(struct ServersScreen* s) {
|
||||
int i;
|
||||
LTable_Sort(&s->table);
|
||||
|
||||
for (i = 0; i < FetchServersTask.NumServers; i++) {
|
||||
FetchFlagsTask_Add(&FetchServersTask.Servers[i]);
|
||||
for (i = 0; i < FetchServersTask.numServers; i++) {
|
||||
FetchFlagsTask_Add(&FetchServersTask.servers[i]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1220,22 +1220,22 @@ static void ServersScreen_Tick(struct LScreen* s_) {
|
||||
int count;
|
||||
LScreen_Tick(s_);
|
||||
|
||||
count = FetchFlagsTask.Count;
|
||||
count = FetchFlagsTask.count;
|
||||
LWebTask_Tick(&FetchFlagsTask.Base);
|
||||
/* TODO: Only redraw flags */
|
||||
if (count != FetchFlagsTask.Count) LWidget_Draw(&s->table);
|
||||
if (count != FetchFlagsTask.count) LWidget_Draw(&s->table);
|
||||
|
||||
if (!FetchServersTask.Base.Working) return;
|
||||
if (!FetchServersTask.Base.working) return;
|
||||
LWebTask_Tick(&FetchServersTask.Base);
|
||||
if (!FetchServersTask.Base.Completed) return;
|
||||
if (!FetchServersTask.Base.completed) return;
|
||||
|
||||
if (FetchServersTask.Base.Success) {
|
||||
if (FetchServersTask.Base.success) {
|
||||
ServersScreen_ReloadServers(s);
|
||||
LWidget_Draw(&s->table);
|
||||
}
|
||||
|
||||
LButton_SetConst(&s->btnRefresh,
|
||||
FetchServersTask.Base.Success ? "Refresh" : "&cFailed");
|
||||
FetchServersTask.Base.success ? "Refresh" : "&cFailed");
|
||||
LWidget_Redraw(&s->btnRefresh);
|
||||
}
|
||||
|
||||
@ -1411,16 +1411,16 @@ static void UpdatesScreen_Format(struct LLabel* lbl, const char* prefix, TimeMS
|
||||
}
|
||||
|
||||
static void UpdatesScreen_FormatBoth(struct UpdatesScreen* s) {
|
||||
UpdatesScreen_Format(&s->lblRel, "Latest release: ", CheckUpdateTask.RelTimestamp);
|
||||
UpdatesScreen_Format(&s->lblDev, "Latest dev build: ", CheckUpdateTask.DevTimestamp);
|
||||
UpdatesScreen_Format(&s->lblRel, "Latest release: ", CheckUpdateTask.relTimestamp);
|
||||
UpdatesScreen_Format(&s->lblDev, "Latest dev build: ", CheckUpdateTask.devTimestamp);
|
||||
}
|
||||
|
||||
static void UpdatesScreen_Get(cc_bool release, cc_bool d3d9) {
|
||||
String str; char strBuffer[STRING_SIZE];
|
||||
struct UpdatesScreen* s = &UpdatesScreen_Instance;
|
||||
|
||||
TimeMS time = release ? CheckUpdateTask.RelTimestamp : CheckUpdateTask.DevTimestamp;
|
||||
if (!time || FetchUpdateTask.Base.Working) return;
|
||||
TimeMS time = release ? CheckUpdateTask.relTimestamp : CheckUpdateTask.devTimestamp;
|
||||
if (!time || FetchUpdateTask.Base.working) return;
|
||||
FetchUpdateTask_Run(release, d3d9);
|
||||
|
||||
if (release && d3d9) s->buildName = "&eFetching latest release (Direct3D9)";
|
||||
@ -1437,9 +1437,9 @@ static void UpdatesScreen_Get(cc_bool release, cc_bool d3d9) {
|
||||
}
|
||||
|
||||
static void UpdatesScreen_CheckTick(struct UpdatesScreen* s) {
|
||||
if (!CheckUpdateTask.Base.Working) return;
|
||||
if (!CheckUpdateTask.Base.working) return;
|
||||
LWebTask_Tick(&CheckUpdateTask.Base);
|
||||
if (!CheckUpdateTask.Base.Completed) return;
|
||||
if (!CheckUpdateTask.Base.completed) return;
|
||||
UpdatesScreen_FormatBoth(s);
|
||||
}
|
||||
|
||||
@ -1451,7 +1451,7 @@ static void UpdatesScreen_UpdateProgress(struct UpdatesScreen* s, struct LWebTas
|
||||
if (!Http_GetCurrent(&item, &progress)) return;
|
||||
|
||||
identifier = String_FromRawArray(item.ID);
|
||||
if (!String_Equals(&identifier, &task->Identifier)) return;
|
||||
if (!String_Equals(&identifier, &task->identifier)) return;
|
||||
if (progress == s->buildProgress) return;
|
||||
|
||||
s->buildProgress = progress;
|
||||
@ -1465,13 +1465,13 @@ static void UpdatesScreen_UpdateProgress(struct UpdatesScreen* s, struct LWebTas
|
||||
|
||||
static void UpdatesScreen_FetchTick(struct UpdatesScreen* s) {
|
||||
String str; char strBuffer[STRING_SIZE];
|
||||
if (!FetchUpdateTask.Base.Working) return;
|
||||
if (!FetchUpdateTask.Base.working) return;
|
||||
|
||||
LWebTask_Tick(&FetchUpdateTask.Base);
|
||||
UpdatesScreen_UpdateProgress(s, &FetchUpdateTask.Base);
|
||||
if (!FetchUpdateTask.Base.Completed) return;
|
||||
if (!FetchUpdateTask.Base.completed) return;
|
||||
|
||||
if (!FetchUpdateTask.Base.Success) {
|
||||
if (!FetchUpdateTask.Base.success) {
|
||||
String_InitArray(str, strBuffer);
|
||||
LWebTask_DisplayError(&FetchUpdateTask.Base, "fetching update", &str);
|
||||
LLabel_SetText(&s->lblStatus, &str);
|
||||
@ -1493,7 +1493,7 @@ static void UpdatesScreen_Update(struct UpdatesScreen* s) {
|
||||
cc_result res;
|
||||
|
||||
/* Initially fill out with update check result from main menu */
|
||||
if (CheckUpdateTask.Base.Completed && CheckUpdateTask.Base.Success) {
|
||||
if (CheckUpdateTask.Base.completed && CheckUpdateTask.Base.success) {
|
||||
UpdatesScreen_FormatBoth(s);
|
||||
}
|
||||
CheckUpdateTask_Run();
|
||||
@ -1567,7 +1567,7 @@ static void UpdatesScreen_Free(struct LScreen* s_) {
|
||||
s->buildName = NULL;
|
||||
s->buildProgress = -1;
|
||||
|
||||
FetchUpdateTask.Base.Working = false;
|
||||
FetchUpdateTask.Base.working = false;
|
||||
s->lblStatus.text.length = 0;
|
||||
}
|
||||
|
||||
|
146
src/LWeb.c
146
src/LWeb.c
@ -197,35 +197,35 @@ static void Json_Handle(cc_uint8* data, cc_uint32 len,
|
||||
*--------------------------------------------------------Web task---------------------------------------------------------*
|
||||
*#########################################################################################################################*/
|
||||
static void LWebTask_Reset(struct LWebTask* task) {
|
||||
task->Completed = false;
|
||||
task->Working = true;
|
||||
task->Success = false;
|
||||
task->Start = DateTime_CurrentUTC_MS();
|
||||
task->Res = 0;
|
||||
task->Status = 0;
|
||||
task->completed = false;
|
||||
task->working = true;
|
||||
task->success = false;
|
||||
task->start = DateTime_CurrentUTC_MS();
|
||||
task->res = 0;
|
||||
task->status = 0;
|
||||
}
|
||||
|
||||
void LWebTask_Tick(struct LWebTask* task) {
|
||||
struct HttpRequest req;
|
||||
int delta;
|
||||
if (task->Completed) return;
|
||||
if (task->completed) return;
|
||||
|
||||
if (!Http_GetResult(&task->Identifier, &req)) return;
|
||||
delta = (int)(DateTime_CurrentUTC_MS() - task->Start);
|
||||
Platform_Log2("%s took %i", &task->Identifier, &delta);
|
||||
if (!Http_GetResult(&task->identifier, &req)) return;
|
||||
delta = (int)(DateTime_CurrentUTC_MS() - task->start);
|
||||
Platform_Log2("%s took %i", &task->identifier, &delta);
|
||||
|
||||
task->Res = req.Result;
|
||||
task->Status = req.StatusCode;
|
||||
task->res = req.Result;
|
||||
task->status = req.StatusCode;
|
||||
|
||||
task->Working = false;
|
||||
task->Completed = true;
|
||||
task->Success = req.Success;
|
||||
if (task->Success) task->Handle((cc_uint8*)req.Data, req.Size);
|
||||
task->working = false;
|
||||
task->completed = true;
|
||||
task->success = req.Success;
|
||||
if (task->success) task->Handle((cc_uint8*)req.Data, req.Size);
|
||||
HttpRequest_Free(&req);
|
||||
}
|
||||
|
||||
void LWebTask_DisplayError(struct LWebTask* task, const char* action, String* dst) {
|
||||
Launcher_DisplayHttpError(task->Res, task->Status, action, dst);
|
||||
Launcher_DisplayHttpError(task->res, task->status, action, dst);
|
||||
}
|
||||
|
||||
|
||||
@ -237,7 +237,7 @@ struct GetTokenTaskData GetTokenTask;
|
||||
|
||||
static void GetTokenTask_OnValue(struct JsonContext* ctx, const String* str) {
|
||||
if (!String_CaselessEqualsConst(&ctx->curKey, "token")) return;
|
||||
String_Copy(&GetTokenTask.Token, str);
|
||||
String_Copy(&GetTokenTask.token, str);
|
||||
}
|
||||
|
||||
static void GetTokenTask_Handle(cc_uint8* data, cc_uint32 len) {
|
||||
@ -248,12 +248,12 @@ void GetTokenTask_Run(void) {
|
||||
static const String id = String_FromConst("CC get token");
|
||||
static const String url = String_FromConst("https://www.classicube.net/api/login");
|
||||
static char tokenBuffer[STRING_SIZE];
|
||||
if (GetTokenTask.Base.Working) return;
|
||||
if (GetTokenTask.Base.working) return;
|
||||
|
||||
LWebTask_Reset(&GetTokenTask.Base);
|
||||
String_InitArray(GetTokenTask.Token, tokenBuffer);
|
||||
String_InitArray(GetTokenTask.token, tokenBuffer);
|
||||
|
||||
GetTokenTask.Base.Identifier = id;
|
||||
GetTokenTask.Base.identifier = id;
|
||||
Http_AsyncGetDataEx(&url, false, &id, NULL, NULL, &ccCookies);
|
||||
GetTokenTask.Base.Handle = GetTokenTask_Handle;
|
||||
}
|
||||
@ -267,17 +267,17 @@ char userBuffer[STRING_SIZE];
|
||||
|
||||
static void SignInTask_LogError(const String* str) {
|
||||
if (String_CaselessEqualsConst(str, "username") || String_CaselessEqualsConst(str, "password")) {
|
||||
SignInTask.Error = "&cWrong username or password";
|
||||
SignInTask.error = "&cWrong username or password";
|
||||
} else if (String_CaselessEqualsConst(str, "verification")) {
|
||||
SignInTask.Error = "&cAccount verification required";
|
||||
SignInTask.error = "&cAccount verification required";
|
||||
} else if (str->length) {
|
||||
SignInTask.Error = "&cUnknown error occurred";
|
||||
SignInTask.error = "&cUnknown error occurred";
|
||||
}
|
||||
}
|
||||
|
||||
static void SignInTask_OnValue(struct JsonContext* ctx, const String* str) {
|
||||
if (String_CaselessEqualsConst(&ctx->curKey, "username")) {
|
||||
String_Copy(&SignInTask.Username, str);
|
||||
String_Copy(&SignInTask.username, str);
|
||||
} else if (String_CaselessEqualsConst(&ctx->curKey, "errors")) {
|
||||
SignInTask_LogError(str);
|
||||
}
|
||||
@ -296,18 +296,18 @@ void SignInTask_Run(const String* user, const String* pass) {
|
||||
static const String id = String_FromConst("CC post login");
|
||||
static const String url = String_FromConst("https://www.classicube.net/api/login");
|
||||
String tmp; char tmpBuffer[384];
|
||||
if (SignInTask.Base.Working) return;
|
||||
if (SignInTask.Base.working) return;
|
||||
|
||||
LWebTask_Reset(&SignInTask.Base);
|
||||
String_InitArray(SignInTask.Username, userBuffer);
|
||||
SignInTask.Error = NULL;
|
||||
String_InitArray(SignInTask.username, userBuffer);
|
||||
SignInTask.error = NULL;
|
||||
|
||||
String_InitArray(tmp, tmpBuffer);
|
||||
SignInTask_Append(&tmp, "username=", user);
|
||||
SignInTask_Append(&tmp, "&password=", pass);
|
||||
SignInTask_Append(&tmp, "&token=", &GetTokenTask.Token);
|
||||
SignInTask_Append(&tmp, "&token=", &GetTokenTask.token);
|
||||
|
||||
SignInTask.Base.Identifier = id;
|
||||
SignInTask.Base.identifier = id;
|
||||
Http_AsyncPostData(&url, false, &id, tmp.buffer, tmp.length, &ccCookies);
|
||||
SignInTask.Base.Handle = SignInTask_Handle;
|
||||
}
|
||||
@ -368,21 +368,21 @@ static void ServerInfo_Parse(struct JsonContext* ctx, const String* val) {
|
||||
}
|
||||
|
||||
static void FetchServerTask_Handle(cc_uint8* data, cc_uint32 len) {
|
||||
curServer = &FetchServerTask.Server;
|
||||
curServer = &FetchServerTask.server;
|
||||
Json_Handle(data, len, ServerInfo_Parse, NULL, NULL);
|
||||
}
|
||||
|
||||
void FetchServerTask_Run(const String* hash) {
|
||||
static const String id = String_FromConst("CC fetch server");
|
||||
String url; char urlBuffer[URL_MAX_SIZE];
|
||||
if (FetchServerTask.Base.Working) return;
|
||||
if (FetchServerTask.Base.working) return;
|
||||
|
||||
LWebTask_Reset(&FetchServerTask.Base);
|
||||
ServerInfo_Init(&FetchServerTask.Server);
|
||||
ServerInfo_Init(&FetchServerTask.server);
|
||||
String_InitArray(url, urlBuffer);
|
||||
String_Format1(&url, "https://www.classicube.net/api/server/%s", hash);
|
||||
|
||||
FetchServerTask.Base.Identifier = id;
|
||||
FetchServerTask.Base.identifier = id;
|
||||
Http_AsyncGetDataEx(&url, false, &id, NULL, NULL, &ccCookies);
|
||||
FetchServerTask.Base.Handle = FetchServerTask_Handle;
|
||||
}
|
||||
@ -393,53 +393,53 @@ void FetchServerTask_Run(const String* hash) {
|
||||
*#########################################################################################################################*/
|
||||
struct FetchServersData FetchServersTask;
|
||||
static void FetchServersTask_Count(struct JsonContext* ctx) {
|
||||
FetchServersTask.NumServers++;
|
||||
FetchServersTask.numServers++;
|
||||
}
|
||||
|
||||
static void FetchServersTask_Next(struct JsonContext* ctx) {
|
||||
curServer++;
|
||||
if (curServer < FetchServersTask.Servers) return;
|
||||
if (curServer < FetchServersTask.servers) return;
|
||||
ServerInfo_Init(curServer);
|
||||
}
|
||||
|
||||
static void FetchServersTask_Handle(cc_uint8* data, cc_uint32 len) {
|
||||
int count;
|
||||
Mem_Free(FetchServersTask.Servers);
|
||||
Mem_Free(FetchServersTask.Orders);
|
||||
Mem_Free(FetchServersTask.servers);
|
||||
Mem_Free(FetchServersTask.orders);
|
||||
|
||||
FetchServersTask.NumServers = 0;
|
||||
FetchServersTask.Servers = NULL;
|
||||
FetchServersTask.Orders = NULL;
|
||||
FetchServersTask.numServers = 0;
|
||||
FetchServersTask.servers = NULL;
|
||||
FetchServersTask.orders = NULL;
|
||||
|
||||
/* -1 because servers is surrounded by a { */
|
||||
FetchServersTask.NumServers = -1;
|
||||
FetchServersTask.numServers = -1;
|
||||
Json_Handle(data, len, NULL, NULL, FetchServersTask_Count);
|
||||
count = FetchServersTask.NumServers;
|
||||
count = FetchServersTask.numServers;
|
||||
|
||||
if (count <= 0) return;
|
||||
FetchServersTask.Servers = (struct ServerInfo*)Mem_Alloc(count, sizeof(struct ServerInfo), "servers list");
|
||||
FetchServersTask.Orders = (cc_uint16*)Mem_Alloc(count, 2, "servers order");
|
||||
FetchServersTask.servers = (struct ServerInfo*)Mem_Alloc(count, sizeof(struct ServerInfo), "servers list");
|
||||
FetchServersTask.orders = (cc_uint16*)Mem_Alloc(count, 2, "servers order");
|
||||
|
||||
/* -2 because servers is surrounded by a { */
|
||||
curServer = FetchServersTask.Servers - 2;
|
||||
curServer = FetchServersTask.servers - 2;
|
||||
Json_Handle(data, len, ServerInfo_Parse, NULL, FetchServersTask_Next);
|
||||
}
|
||||
|
||||
void FetchServersTask_Run(void) {
|
||||
static const String id = String_FromConst("CC fetch servers");
|
||||
static const String url = String_FromConst("https://www.classicube.net/api/servers");
|
||||
if (FetchServersTask.Base.Working) return;
|
||||
if (FetchServersTask.Base.working) return;
|
||||
LWebTask_Reset(&FetchServersTask.Base);
|
||||
|
||||
FetchServersTask.Base.Identifier = id;
|
||||
FetchServersTask.Base.identifier = id;
|
||||
Http_AsyncGetDataEx(&url, false, &id, NULL, NULL, &ccCookies);
|
||||
FetchServersTask.Base.Handle = FetchServersTask_Handle;
|
||||
}
|
||||
|
||||
void FetchServersTask_ResetOrder(void) {
|
||||
int i;
|
||||
for (i = 0; i < FetchServersTask.NumServers; i++) {
|
||||
FetchServersTask.Orders[i] = i;
|
||||
for (i = 0; i < FetchServersTask.numServers; i++) {
|
||||
FetchServersTask.orders[i] = i;
|
||||
}
|
||||
}
|
||||
|
||||
@ -464,11 +464,11 @@ CC_NOINLINE static TimeMS CheckUpdateTask_ParseTime(const String* str) {
|
||||
|
||||
static void CheckUpdateTask_OnValue(struct JsonContext* ctx, const String* str) {
|
||||
if (String_CaselessEqualsConst(&ctx->curKey, "release_version")) {
|
||||
String_Copy(&CheckUpdateTask.LatestRelease, str);
|
||||
String_Copy(&CheckUpdateTask.latestRelease, str);
|
||||
} else if (String_CaselessEqualsConst(&ctx->curKey, "latest_ts")) {
|
||||
CheckUpdateTask.DevTimestamp = CheckUpdateTask_ParseTime(str);
|
||||
CheckUpdateTask.devTimestamp = CheckUpdateTask_ParseTime(str);
|
||||
} else if (String_CaselessEqualsConst(&ctx->curKey, "release_ts")) {
|
||||
CheckUpdateTask.RelTimestamp = CheckUpdateTask_ParseTime(str);
|
||||
CheckUpdateTask.relTimestamp = CheckUpdateTask_ParseTime(str);
|
||||
}
|
||||
}
|
||||
|
||||
@ -479,14 +479,14 @@ static void CheckUpdateTask_Handle(cc_uint8* data, cc_uint32 len) {
|
||||
void CheckUpdateTask_Run(void) {
|
||||
static const String id = String_FromConst("CC update check");
|
||||
static const String url = String_FromConst("http://cs.classicube.net/c_client/builds.json");
|
||||
if (CheckUpdateTask.Base.Working) return;
|
||||
if (CheckUpdateTask.Base.working) return;
|
||||
|
||||
LWebTask_Reset(&CheckUpdateTask.Base);
|
||||
CheckUpdateTask.DevTimestamp = 0;
|
||||
CheckUpdateTask.RelTimestamp = 0;
|
||||
String_InitArray(CheckUpdateTask.LatestRelease, relVersionBuffer);
|
||||
CheckUpdateTask.devTimestamp = 0;
|
||||
CheckUpdateTask.relTimestamp = 0;
|
||||
String_InitArray(CheckUpdateTask.latestRelease, relVersionBuffer);
|
||||
|
||||
CheckUpdateTask.Base.Identifier = id;
|
||||
CheckUpdateTask.Base.identifier = id;
|
||||
Http_AsyncGetData(&url, false, &id);
|
||||
CheckUpdateTask.Base.Handle = CheckUpdateTask_Handle;
|
||||
}
|
||||
@ -503,7 +503,7 @@ static void FetchUpdateTask_Handle(cc_uint8* data, cc_uint32 len) {
|
||||
res = Stream_WriteAllTo(&path, data, len);
|
||||
if (res) { Logger_Warn(res, "saving update"); return; }
|
||||
|
||||
res = File_SetModifiedTime(&path, FetchUpdateTask.Timestamp);
|
||||
res = File_SetModifiedTime(&path, FetchUpdateTask.timestamp);
|
||||
if (res) Logger_Warn(res, "setting update time");
|
||||
|
||||
res = File_MarkExecutable(&path);
|
||||
@ -555,8 +555,8 @@ void FetchUpdateTask_Run(cc_bool release, cc_bool d3d9) {
|
||||
String url; char urlBuffer[URL_MAX_SIZE];
|
||||
String_InitArray(url, urlBuffer);
|
||||
|
||||
String_InitArray(FetchUpdateTask.Base.Identifier, idBuffer);
|
||||
String_Format1(&FetchUpdateTask.Base.Identifier, "CC update fetch%i", &idCounter);
|
||||
String_InitArray(FetchUpdateTask.Base.identifier, idBuffer);
|
||||
String_Format1(&FetchUpdateTask.Base.identifier, "CC update fetch%i", &idCounter);
|
||||
/* User may click another update button in the updates menu before original update finished downloading */
|
||||
/* Hence must use a different ID for each update fetch, otherwise old update gets downloaded and applied */
|
||||
idCounter++;
|
||||
@ -564,12 +564,12 @@ void FetchUpdateTask_Run(cc_bool release, cc_bool d3d9) {
|
||||
String_Format2(&url, "http://cs.classicube.net/c_client/%c/%c",
|
||||
release ? "release" : "latest",
|
||||
d3d9 ? exe_d3d9 : exe_ogl);
|
||||
if (FetchUpdateTask.Base.Working) return;
|
||||
if (FetchUpdateTask.Base.working) return;
|
||||
|
||||
LWebTask_Reset(&FetchUpdateTask.Base);
|
||||
FetchUpdateTask.Timestamp = release ? CheckUpdateTask.RelTimestamp : CheckUpdateTask.DevTimestamp;
|
||||
FetchUpdateTask.timestamp = release ? CheckUpdateTask.relTimestamp : CheckUpdateTask.devTimestamp;
|
||||
|
||||
Http_AsyncGetData(&url, false, &FetchUpdateTask.Base.Identifier);
|
||||
Http_AsyncGetData(&url, false, &FetchUpdateTask.Base.identifier);
|
||||
FetchUpdateTask.Base.Handle = FetchUpdateTask_Handle;
|
||||
}
|
||||
|
||||
@ -607,11 +607,11 @@ static void FetchFlagsTask_Handle(cc_uint8* data, cc_uint32 len) {
|
||||
cc_result res;
|
||||
|
||||
Stream_ReadonlyMemory(&s, data, len);
|
||||
res = Png_Decode(&flags[FetchFlagsTask.Count].bmp, &s);
|
||||
res = Png_Decode(&flags[FetchFlagsTask.count].bmp, &s);
|
||||
if (res) Logger_Warn(res, "decoding flag");
|
||||
|
||||
FetchFlagsTask_Scale(&flags[FetchFlagsTask.Count].bmp);
|
||||
FetchFlagsTask.Count++;
|
||||
FetchFlagsTask_Scale(&flags[FetchFlagsTask.count].bmp);
|
||||
FetchFlagsTask.count++;
|
||||
FetchFlagsTask_DownloadNext();
|
||||
}
|
||||
|
||||
@ -620,14 +620,14 @@ static void FetchFlagsTask_DownloadNext(void) {
|
||||
String url; char urlBuffer[URL_MAX_SIZE];
|
||||
String_InitArray(url, urlBuffer);
|
||||
|
||||
if (FetchFlagsTask.Base.Working) return;
|
||||
if (FetchFlagsTask.Count == flagsCount) return;
|
||||
if (FetchFlagsTask.Base.working) return;
|
||||
if (FetchFlagsTask.count == flagsCount) return;
|
||||
|
||||
LWebTask_Reset(&FetchFlagsTask.Base);
|
||||
String_Format2(&url, "http://static.classicube.net/img/flags/%r%r.png",
|
||||
&flags[FetchFlagsTask.Count].country[0], &flags[FetchFlagsTask.Count].country[1]);
|
||||
&flags[FetchFlagsTask.count].country[0], &flags[FetchFlagsTask.count].country[1]);
|
||||
|
||||
FetchFlagsTask.Base.Identifier = id;
|
||||
FetchFlagsTask.Base.identifier = id;
|
||||
Http_AsyncGetData(&url, false, &id);
|
||||
FetchFlagsTask.Base.Handle = FetchFlagsTask_Handle;
|
||||
}
|
||||
@ -663,7 +663,7 @@ void FetchFlagsTask_Add(const struct ServerInfo* server) {
|
||||
|
||||
Bitmap* Flags_Get(const struct ServerInfo* server) {
|
||||
int i;
|
||||
for (i = 0; i < FetchFlagsTask.Count; i++) {
|
||||
for (i = 0; i < FetchFlagsTask.count; i++) {
|
||||
if (flags[i].country[0] != server->country[0]) continue;
|
||||
if (flags[i].country[1] != server->country[1]) continue;
|
||||
return &flags[i].bmp;
|
||||
@ -673,7 +673,7 @@ Bitmap* Flags_Get(const struct ServerInfo* server) {
|
||||
|
||||
void Flags_Free(void) {
|
||||
int i;
|
||||
for (i = 0; i < FetchFlagsTask.Count; i++) {
|
||||
for (i = 0; i < FetchFlagsTask.count; i++) {
|
||||
Mem_Free(flags[i].bmp.Scan0);
|
||||
}
|
||||
}
|
||||
|
41
src/LWeb.h
41
src/LWeb.h
@ -41,17 +41,16 @@ struct ServerInfo {
|
||||
char _softBuffer[STRING_SIZE];
|
||||
};
|
||||
|
||||
struct LWebTask;
|
||||
struct LWebTask {
|
||||
cc_bool Completed; /* Whether the task has finished executing. */
|
||||
cc_bool Working; /* Whether the task is currently in progress, or is scheduled to be. */
|
||||
cc_bool Success; /* Whether the task completed successfully. */
|
||||
cc_result Res; /* Error returned (e.g. for DNS failure) */
|
||||
int Status; /* HTTP return code for the request */
|
||||
cc_bool completed; /* Whether the task has finished executing. */
|
||||
cc_bool working; /* Whether the task is currently in progress, or is scheduled to be. */
|
||||
cc_bool success; /* Whether the task completed successfully. */
|
||||
cc_result res; /* Error returned (e.g. for DNS failure) */
|
||||
int status; /* HTTP return code for the request */
|
||||
|
||||
String Identifier; /* Unique identifier for this web task. */
|
||||
String URL; /* URL this task is downloading from/uploading to. */
|
||||
TimeMS Start; /* Point in time this task was started at. */
|
||||
String identifier; /* Unique identifier for this web task. */
|
||||
String url; /* URL this task is downloading from/uploading to. */
|
||||
TimeMS start; /* Point in time this task was started at. */
|
||||
/* Called when task successfully downloaded/uploaded data. */
|
||||
void (*Handle)(cc_uint8* data, cc_uint32 len);
|
||||
};
|
||||
@ -61,42 +60,42 @@ void LWebTask_DisplayError(struct LWebTask* task, const char* action, String* ds
|
||||
|
||||
extern struct GetTokenTaskData {
|
||||
struct LWebTask Base;
|
||||
String Token; /* Random CSRF token for logging in. */
|
||||
String token; /* Random CSRF token for logging in. */
|
||||
} GetTokenTask;
|
||||
void GetTokenTask_Run(void);
|
||||
|
||||
extern struct SignInTaskData {
|
||||
struct LWebTask Base;
|
||||
String Username; /* Username to sign in as. Changed to case correct username. */
|
||||
const char* Error; /* If sign in fails, the reason as to why. */
|
||||
String username; /* Username to sign in as. Changed to case correct username. */
|
||||
const char* error; /* If sign in fails, the reason as to why. */
|
||||
} SignInTask;
|
||||
void SignInTask_Run(const String* user, const String* pass);
|
||||
|
||||
|
||||
extern struct FetchServerData {
|
||||
struct LWebTask Base;
|
||||
struct ServerInfo Server; /* Details about the given server on success. */
|
||||
struct ServerInfo server; /* Details about the given server on success. */
|
||||
} FetchServerTask;
|
||||
void FetchServerTask_Run(const String* hash);
|
||||
|
||||
|
||||
extern struct FetchServersData {
|
||||
struct LWebTask Base;
|
||||
struct ServerInfo* Servers; /* List of all public servers on server list. */
|
||||
cc_uint16* Orders; /* Order of each server (after sorting) */
|
||||
int NumServers; /* Number of public servers. */
|
||||
struct ServerInfo* servers; /* List of all public servers on server list. */
|
||||
cc_uint16* orders; /* Order of each server (after sorting) */
|
||||
int numServers; /* Number of public servers. */
|
||||
} FetchServersTask;
|
||||
void FetchServersTask_Run(void);
|
||||
void FetchServersTask_ResetOrder(void);
|
||||
#define Servers_Get(i) (&FetchServersTask.Servers[FetchServersTask.Orders[i]])
|
||||
#define Servers_Get(i) (&FetchServersTask.servers[FetchServersTask.orders[i]])
|
||||
|
||||
|
||||
extern struct CheckUpdateData {
|
||||
struct LWebTask Base;
|
||||
/* Timestamp latest commit/dev build and release were at. */
|
||||
TimeMS DevTimestamp, RelTimestamp;
|
||||
TimeMS devTimestamp, relTimestamp;
|
||||
/* Version of latest release. */
|
||||
String LatestRelease;
|
||||
String latestRelease;
|
||||
} CheckUpdateTask; /* TODO: Work out the JSON for this.. */
|
||||
void CheckUpdateTask_Run(void);
|
||||
|
||||
@ -104,7 +103,7 @@ void CheckUpdateTask_Run(void);
|
||||
extern struct FetchUpdateData {
|
||||
struct LWebTask Base;
|
||||
/* Timestamp downloaded build was originally built at. */
|
||||
TimeMS Timestamp;
|
||||
TimeMS timestamp;
|
||||
} FetchUpdateTask;
|
||||
void FetchUpdateTask_Run(cc_bool release, cc_bool d3d9);
|
||||
|
||||
@ -112,7 +111,7 @@ void FetchUpdateTask_Run(cc_bool release, cc_bool d3d9);
|
||||
extern struct FetchFlagsData {
|
||||
struct LWebTask Base;
|
||||
/* Number of flags downloaded. */
|
||||
int Count;
|
||||
int count;
|
||||
} FetchFlagsTask;
|
||||
/* Asynchronously downloads the flag associated with the given server's country. */
|
||||
void FetchFlagsTask_Add(const struct ServerInfo* server);
|
||||
|
@ -1124,16 +1124,16 @@ void LTable_Reset(struct LTable* w) {
|
||||
void LTable_ApplyFilter(struct LTable* w) {
|
||||
int i, j, count;
|
||||
|
||||
count = FetchServersTask.NumServers;
|
||||
count = FetchServersTask.numServers;
|
||||
for (i = 0, j = 0; i < count; i++) {
|
||||
if (String_CaselessContains(&Servers_Get(i)->name, w->filter)) {
|
||||
FetchServersTask.Servers[j++]._order = FetchServersTask.Orders[i];
|
||||
FetchServersTask.servers[j++]._order = FetchServersTask.orders[i];
|
||||
}
|
||||
}
|
||||
|
||||
w->rowsCount = j;
|
||||
for (; j < count; j++) {
|
||||
FetchServersTask.Servers[j]._order = -100000;
|
||||
FetchServersTask.servers[j]._order = -100000;
|
||||
}
|
||||
|
||||
w->_lastRow = -1;
|
||||
@ -1153,7 +1153,7 @@ static int LTable_SortOrder(const struct ServerInfo* a, const struct ServerInfo*
|
||||
}
|
||||
|
||||
static void LTable_QuickSort(int left, int right) {
|
||||
cc_uint16* keys = FetchServersTask.Orders; cc_uint16 key;
|
||||
cc_uint16* keys = FetchServersTask.orders; cc_uint16 key;
|
||||
|
||||
while (left < right) {
|
||||
int i = left, j = right;
|
||||
@ -1171,9 +1171,9 @@ static void LTable_QuickSort(int left, int right) {
|
||||
}
|
||||
|
||||
void LTable_Sort(struct LTable* w) {
|
||||
if (!FetchServersTask.NumServers) return;
|
||||
if (!FetchServersTask.numServers) return;
|
||||
FetchServersTask_ResetOrder();
|
||||
LTable_QuickSort(0, FetchServersTask.NumServers - 1);
|
||||
LTable_QuickSort(0, FetchServersTask.numServers - 1);
|
||||
|
||||
LTable_ApplyFilter(w);
|
||||
LTable_ShowSelected(w);
|
||||
|
@ -184,7 +184,7 @@ struct LTable {
|
||||
TimeMS _lastClick; /* time of last mouse click on a row */
|
||||
};
|
||||
/* Gets the current ith row */
|
||||
#define LTable_Get(row) (&FetchServersTask.Servers[FetchServersTask.Servers[row]._order])
|
||||
#define LTable_Get(row) (&FetchServersTask.servers[FetchServersTask.servers[row]._order])
|
||||
|
||||
/* Initialises a table. */
|
||||
/* NOTE: Must also call LTable_Reset to make a table actually useful. */
|
||||
|
@ -46,7 +46,7 @@ CC_NOINLINE static void Launcher_StartFromInfo(struct ServerInfo* info) {
|
||||
String_InitArray(port, portBuffer);
|
||||
|
||||
String_AppendInt(&port, info->port);
|
||||
Launcher_StartGame(&SignInTask.Username, &info->mppass, &info->ip, &port, &info->name);
|
||||
Launcher_StartGame(&SignInTask.username, &info->mppass, &info->ip, &port, &info->name);
|
||||
}
|
||||
|
||||
cc_bool Launcher_ConnectToServer(const String* hash) {
|
||||
@ -55,8 +55,8 @@ cc_bool Launcher_ConnectToServer(const String* hash) {
|
||||
int i;
|
||||
if (!hash->length) return false;
|
||||
|
||||
for (i = 0; i < FetchServersTask.NumServers; i++) {
|
||||
info = &FetchServersTask.Servers[i];
|
||||
for (i = 0; i < FetchServersTask.numServers; i++) {
|
||||
info = &FetchServersTask.servers[i];
|
||||
if (!String_Equals(hash, &info->hash)) continue;
|
||||
|
||||
Launcher_StartFromInfo(info);
|
||||
@ -67,15 +67,15 @@ cc_bool Launcher_ConnectToServer(const String* hash) {
|
||||
/* TODO: Rewrite to be async */
|
||||
FetchServerTask_Run(hash);
|
||||
|
||||
while (!FetchServerTask.Base.Completed) {
|
||||
while (!FetchServerTask.Base.completed) {
|
||||
LWebTask_Tick(&FetchServerTask.Base);
|
||||
Thread_Sleep(10);
|
||||
}
|
||||
|
||||
if (FetchServerTask.Server.hash.length) {
|
||||
Launcher_StartFromInfo(&FetchServerTask.Server);
|
||||
if (FetchServerTask.server.hash.length) {
|
||||
Launcher_StartFromInfo(&FetchServerTask.server);
|
||||
return true;
|
||||
} else if (FetchServerTask.Base.Success) {
|
||||
} else if (FetchServerTask.Base.success) {
|
||||
Window_ShowDialog("Failed to connect", "No server has that hash");
|
||||
} else {
|
||||
logMsg = String_Init(NULL, 0, 0);
|
||||
|
@ -62,7 +62,7 @@ static float RayTracer_Div(float a, float b) {
|
||||
return a / b;
|
||||
}
|
||||
|
||||
void RayTracer_SetVectors(struct RayTracer* t, Vec3 origin, Vec3 dir) {
|
||||
void RayTracer_Init(struct RayTracer* t, Vec3 origin, Vec3 dir) {
|
||||
IVec3 start, cellBoundary;
|
||||
t->Origin = origin; t->Dir = dir;
|
||||
|
||||
@ -161,7 +161,7 @@ static cc_bool Picking_RayTrace(Vec3 origin, Vec3 dir, float reach, struct Picke
|
||||
float dzMin, dzMax, dz;
|
||||
int i, x, y, z;
|
||||
|
||||
RayTracer_SetVectors(&tracer, origin, dir);
|
||||
RayTracer_Init(&tracer, origin, dir);
|
||||
IVec3_Floor(&pOrigin, &origin);
|
||||
insideMap = World_Contains(pOrigin.X, pOrigin.Y, pOrigin.Z);
|
||||
reachSq = reach * reach;
|
||||
|
@ -38,7 +38,7 @@ struct RayTracer {
|
||||
|
||||
void PickedPos_SetAsValid(struct PickedPos* pos, struct RayTracer* t, Vec3 intersect);
|
||||
void PickedPos_SetAsInvalid(struct PickedPos* pos);
|
||||
void RayTracer_SetVectors(struct RayTracer* t, Vec3 origin, Vec3 dir);
|
||||
void RayTracer_Init(struct RayTracer* t, Vec3 origin, Vec3 dir);
|
||||
void RayTracer_Step(struct RayTracer* t);
|
||||
|
||||
/* Determines the picked block based on the given origin and direction vector.
|
||||
|
Loading…
x
Reference in New Issue
Block a user