mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-14 01:55:19 -04:00
Minor tidyup in Chat.c
This commit is contained in:
parent
0f197708e8
commit
ff115a1753
46
src/Chat.c
46
src/Chat.c
@ -35,7 +35,7 @@ static TimeMS defaultLogTimes[CHAT_LOGTIMES_DEF_ELEMS];
|
|||||||
static int logTimesCapacity = CHAT_LOGTIMES_DEF_ELEMS, logTimesCount;
|
static int logTimesCapacity = CHAT_LOGTIMES_DEF_ELEMS, logTimesCount;
|
||||||
TimeMS* Chat_LogTime = defaultLogTimes;
|
TimeMS* Chat_LogTime = defaultLogTimes;
|
||||||
|
|
||||||
static void Chat_AppendLogTime(void) {
|
static void AppendChatLogTime(void) {
|
||||||
TimeMS now = DateTime_CurrentUTC_MS();
|
TimeMS now = DateTime_CurrentUTC_MS();
|
||||||
|
|
||||||
if (logTimesCount == logTimesCapacity) {
|
if (logTimesCount == logTimesCapacity) {
|
||||||
@ -46,11 +46,11 @@ static void Chat_AppendLogTime(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef CC_BUILD_WEB
|
#ifdef CC_BUILD_WEB
|
||||||
static void Chat_ResetLog(void) { }
|
static void ResetLogFile(void) { }
|
||||||
static void Chat_CloseLog(void) { }
|
static void CloseLogFile(void) { }
|
||||||
void Chat_SetLogName(const String* name) { }
|
void Chat_SetLogName(const String* name) { }
|
||||||
static void Chat_OpenLog(struct DateTime* now) { }
|
static void OpenChatLog(struct DateTime* now) { }
|
||||||
static void Chat_AppendLog(const String* text) { }
|
static void AppendChatLog(const String* text) { }
|
||||||
#else
|
#else
|
||||||
static char logNameBuffer[STRING_SIZE];
|
static char logNameBuffer[STRING_SIZE];
|
||||||
static String logName = String_FromArray(logNameBuffer);
|
static String logName = String_FromArray(logNameBuffer);
|
||||||
@ -61,7 +61,7 @@ static struct Stream logStream;
|
|||||||
static struct DateTime lastLogDate;
|
static struct DateTime lastLogDate;
|
||||||
|
|
||||||
/* Resets log name to empty and last log date to 0 */
|
/* Resets log name to empty and last log date to 0 */
|
||||||
static void Chat_ResetLog(void) {
|
static void ResetLogFile(void) {
|
||||||
logName.length = 0;
|
logName.length = 0;
|
||||||
lastLogDate.day = 0;
|
lastLogDate.day = 0;
|
||||||
lastLogDate.month = 0;
|
lastLogDate.month = 0;
|
||||||
@ -69,7 +69,7 @@ static void Chat_ResetLog(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Closes handle to the chat log file */
|
/* Closes handle to the chat log file */
|
||||||
static void Chat_CloseLog(void) {
|
static void CloseLogFile(void) {
|
||||||
cc_result res;
|
cc_result res;
|
||||||
if (!logStream.Meta.File) return;
|
if (!logStream.Meta.File) return;
|
||||||
|
|
||||||
@ -78,7 +78,7 @@ static void Chat_CloseLog(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Whether the given character is an allowed in a log filename */
|
/* Whether the given character is an allowed in a log filename */
|
||||||
static cc_bool Chat_AllowedLogChar(char c) {
|
static cc_bool AllowedLogNameChar(char c) {
|
||||||
return
|
return
|
||||||
c == '{' || c == '}' || c == '[' || c == ']' || c == '(' || c == ')' ||
|
c == '{' || c == '}' || c == '[' || c == ']' || c == '(' || c == ')' ||
|
||||||
(c >= '0' && c <= '9') || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z');
|
(c >= '0' && c <= '9') || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z');
|
||||||
@ -92,7 +92,7 @@ void Chat_SetLogName(const String* name) {
|
|||||||
for (i = 0; i < name->length; i++) {
|
for (i = 0; i < name->length; i++) {
|
||||||
c = name->buffer[i];
|
c = name->buffer[i];
|
||||||
|
|
||||||
if (Chat_AllowedLogChar(c)) {
|
if (AllowedLogNameChar(c)) {
|
||||||
String_Append(&logName, c);
|
String_Append(&logName, c);
|
||||||
} else if (c == '&') {
|
} else if (c == '&') {
|
||||||
i++; /* skip over following colour code */
|
i++; /* skip over following colour code */
|
||||||
@ -100,15 +100,15 @@ void Chat_SetLogName(const String* name) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void Chat_DisableLogging(void) {
|
static void DisableChatLogging(void) {
|
||||||
Chat_Logging = false;
|
Chat_Logging = false;
|
||||||
Chat_AddRaw("&cDisabling chat logging");
|
Chat_AddRaw("&cDisabling chat logging");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void Chat_OpenLog(struct DateTime* now) {
|
static void OpenChatLog(struct DateTime* now) {
|
||||||
cc_result res;
|
cc_result res;
|
||||||
int i;
|
int i;
|
||||||
if (!Utils_EnsureDirectory("logs")) { Chat_DisableLogging(); return; }
|
if (!Utils_EnsureDirectory("logs")) { DisableChatLogging(); return; }
|
||||||
|
|
||||||
/* Ensure multiple instances do not end up overwriting each other's log entries. */
|
/* Ensure multiple instances do not end up overwriting each other's log entries. */
|
||||||
for (i = 0; i < 20; i++) {
|
for (i = 0; i < 20; i++) {
|
||||||
@ -123,7 +123,7 @@ static void Chat_OpenLog(struct DateTime* now) {
|
|||||||
|
|
||||||
res = Stream_AppendFile(&logStream, &logPath);
|
res = Stream_AppendFile(&logStream, &logPath);
|
||||||
if (res && res != ReturnCode_FileShareViolation) {
|
if (res && res != ReturnCode_FileShareViolation) {
|
||||||
Chat_DisableLogging();
|
DisableChatLogging();
|
||||||
Logger_Warn2(res, "appending to", &logPath);
|
Logger_Warn2(res, "appending to", &logPath);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -133,11 +133,11 @@ static void Chat_OpenLog(struct DateTime* now) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
logStream.Meta.File = 0;
|
logStream.Meta.File = 0;
|
||||||
Chat_DisableLogging();
|
DisableChatLogging();
|
||||||
Chat_Add1("&cFailed to open a chat log file after %i tries, giving up", &i);
|
Chat_Add1("&cFailed to open a chat log file after %i tries, giving up", &i);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void Chat_AppendLog(const String* text) {
|
static void AppendChatLog(const String* text) {
|
||||||
String str; char strBuffer[STRING_SIZE * 2];
|
String str; char strBuffer[STRING_SIZE * 2];
|
||||||
struct DateTime now;
|
struct DateTime now;
|
||||||
cc_result res;
|
cc_result res;
|
||||||
@ -146,8 +146,8 @@ static void Chat_AppendLog(const String* text) {
|
|||||||
DateTime_CurrentLocal(&now);
|
DateTime_CurrentLocal(&now);
|
||||||
|
|
||||||
if (now.day != lastLogDate.day || now.month != lastLogDate.month || now.year != lastLogDate.year) {
|
if (now.day != lastLogDate.day || now.month != lastLogDate.month || now.year != lastLogDate.year) {
|
||||||
Chat_CloseLog();
|
CloseLogFile();
|
||||||
Chat_OpenLog(&now);
|
OpenChatLog(&now);
|
||||||
}
|
}
|
||||||
|
|
||||||
lastLogDate = now;
|
lastLogDate = now;
|
||||||
@ -160,7 +160,7 @@ static void Chat_AppendLog(const String* text) {
|
|||||||
|
|
||||||
res = Stream_WriteLine(&logStream, &str);
|
res = Stream_WriteLine(&logStream, &str);
|
||||||
if (!res) return;
|
if (!res) return;
|
||||||
Chat_DisableLogging();
|
DisableChatLogging();
|
||||||
Logger_Warn2(res, "writing to", &logPath);
|
Logger_Warn2(res, "writing to", &logPath);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -191,8 +191,8 @@ void Chat_Add(const String* text) { Chat_AddOf(text, MSG_TYPE_NORMAL); }
|
|||||||
void Chat_AddOf(const String* text, int msgType) {
|
void Chat_AddOf(const String* text, int msgType) {
|
||||||
if (msgType == MSG_TYPE_NORMAL) {
|
if (msgType == MSG_TYPE_NORMAL) {
|
||||||
StringsBuffer_Add(&Chat_Log, text);
|
StringsBuffer_Add(&Chat_Log, text);
|
||||||
Chat_AppendLogTime();
|
AppendChatLogTime();
|
||||||
Chat_AppendLog(text);
|
AppendChatLog(text);
|
||||||
} else if (msgType >= MSG_TYPE_STATUS_1 && msgType <= MSG_TYPE_STATUS_3) {
|
} else if (msgType >= MSG_TYPE_STATUS_1 && msgType <= MSG_TYPE_STATUS_3) {
|
||||||
/* Status[0] is for texture pack downloading message */
|
/* Status[0] is for texture pack downloading message */
|
||||||
String_Copy(&Chat_Status[1 + (msgType - MSG_TYPE_STATUS_1)], text);
|
String_Copy(&Chat_Status[1 + (msgType - MSG_TYPE_STATUS_1)], text);
|
||||||
@ -607,8 +607,8 @@ static void Chat_Init(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void Chat_Reset(void) {
|
static void Chat_Reset(void) {
|
||||||
Chat_CloseLog();
|
CloseLogFile();
|
||||||
Chat_ResetLog();
|
ResetLogFile();
|
||||||
|
|
||||||
/* reset CPE messages */
|
/* reset CPE messages */
|
||||||
Chat_AddOf(&String_Empty, MSG_TYPE_ANNOUNCEMENT);
|
Chat_AddOf(&String_Empty, MSG_TYPE_ANNOUNCEMENT);
|
||||||
@ -621,7 +621,7 @@ static void Chat_Reset(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void Chat_Free(void) {
|
static void Chat_Free(void) {
|
||||||
Chat_CloseLog();
|
CloseLogFile();
|
||||||
cmds_head = NULL;
|
cmds_head = NULL;
|
||||||
|
|
||||||
if (Chat_LogTime != defaultLogTimes) Mem_Free(Chat_LogTime);
|
if (Chat_LogTime != defaultLogTimes) Mem_Free(Chat_LogTime);
|
||||||
|
@ -247,7 +247,7 @@ static int Logger_GetFrames(CONTEXT* ctx, cc_uintptr* addrs, int max) {
|
|||||||
frame.AddrFrame.Offset = ctx->Rsp;
|
frame.AddrFrame.Offset = ctx->Rsp;
|
||||||
frame.AddrStack.Offset = ctx->Rsp;
|
frame.AddrStack.Offset = ctx->Rsp;
|
||||||
#else
|
#else
|
||||||
#error "Unknown machine type"
|
#error "Unknown CPU architecture"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
HANDLE process = GetCurrentProcess();
|
HANDLE process = GetCurrentProcess();
|
||||||
|
10
src/Server.c
10
src/Server.c
@ -152,7 +152,7 @@ static void SPConnection_BeginConnect(void) {
|
|||||||
GeneratingScreen_Show();
|
GeneratingScreen_Show();
|
||||||
}
|
}
|
||||||
|
|
||||||
static char SPConnection_LastCol = '\0';
|
static char sp_lastCol = '\0';
|
||||||
static void SPConnection_AddPart(const String* text) {
|
static void SPConnection_AddPart(const String* text) {
|
||||||
String tmp; char tmpBuffer[STRING_SIZE * 2];
|
String tmp; char tmpBuffer[STRING_SIZE * 2];
|
||||||
char col;
|
char col;
|
||||||
@ -160,9 +160,9 @@ static void SPConnection_AddPart(const String* text) {
|
|||||||
String_InitArray(tmp, tmpBuffer);
|
String_InitArray(tmp, tmpBuffer);
|
||||||
|
|
||||||
/* Prepend colour codes for subsequent lines of multi-line chat */
|
/* Prepend colour codes for subsequent lines of multi-line chat */
|
||||||
if (!Drawer2D_IsWhiteCol(SPConnection_LastCol)) {
|
if (!Drawer2D_IsWhiteCol(sp_lastCol)) {
|
||||||
String_Append(&tmp, '&');
|
String_Append(&tmp, '&');
|
||||||
String_Append(&tmp, SPConnection_LastCol);
|
String_Append(&tmp, sp_lastCol);
|
||||||
}
|
}
|
||||||
String_AppendString(&tmp, text);
|
String_AppendString(&tmp, text);
|
||||||
|
|
||||||
@ -173,7 +173,7 @@ static void SPConnection_AddPart(const String* text) {
|
|||||||
String_UNSAFE_TrimEnd(&tmp);
|
String_UNSAFE_TrimEnd(&tmp);
|
||||||
|
|
||||||
col = Drawer2D_LastCol(&tmp, tmp.length);
|
col = Drawer2D_LastCol(&tmp, tmp.length);
|
||||||
if (col) SPConnection_LastCol = col;
|
if (col) sp_lastCol = col;
|
||||||
Chat_Add(&tmp);
|
Chat_Add(&tmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -185,7 +185,7 @@ static void SPConnection_SendChat(const String* text) {
|
|||||||
String left, part;
|
String left, part;
|
||||||
if (!text->length) return;
|
if (!text->length) return;
|
||||||
|
|
||||||
SPConnection_LastCol = '\0';
|
sp_lastCol = '\0';
|
||||||
left = *text;
|
left = *text;
|
||||||
|
|
||||||
while (left.length > STRING_SIZE) {
|
while (left.length > STRING_SIZE) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user