This commit is contained in:
izac112
2020-05-28 23:53:36 +02:00
22 changed files with 1062 additions and 65 deletions

View File

@@ -138,8 +138,9 @@ GLOBAL_DATUM_INIT(iconCache, /savefile, new("data/iconCache.sav")) //Cache of ic
//Perform DB shenanigans
/datum/chatOutput/proc/load_database()
set waitfor = FALSE
var/list/results = vchat_get_messages(owner.ckey) //If there's bad performance on reconnects, look no further
for(var/i in max(1, results.len - message_buffer)) // Only send them the number of buffered messages, instead of the ENTIRE log
// Only send them the number of buffered messages, instead of the ENTIRE log
var/list/results = vchat_get_messages(owner.ckey, message_buffer) //If there's bad performance on reconnects, look no further
for(var/i in results.len to 1 step -1)
var/list/message = results[i]
var/count = 10
to_chat_immediate(owner, message["time"], message["message"])
@@ -367,15 +368,13 @@ var/to_chat_src
time = world.time
var/client/C = CLIENT_FROM_VAR(target)
if(C && C.chatOutput)
if(C.chatOutput.broken)
DIRECT_OUTPUT(C, original_message)
return
// // Client still loading, put their messages in a queue - Actually don't, logged already in database.
// if(!C.chatOutput.loaded && C.chatOutput.message_queue && islist(C.chatOutput.message_queue))
// C.chatOutput.message_queue[++C.chatOutput.message_queue.len] = list("time" = time, "message" = message)
// return
if(!C)
return // No client? No care.
else if(C.chatOutput.broken)
DIRECT_OUTPUT(C, original_message)
return
else if(!C.chatOutput.loaded)
return // If not loaded yet, do nothing and history-sending on load will get it.
var/list/tojson = list("time" = time, "message" = message);
target << output(jsEncode(tojson), "htmloutput:putmessage")

View File

@@ -108,12 +108,16 @@ GLOBAL_DATUM(vchatdb, /database)
return vchat_exec_update(messagedef)
//Get a player's message history
/proc/vchat_get_messages(var/ckey, var/oldest = 0)
//Get a player's message history. If limit is supplied, messages will be in reverse order.
/proc/vchat_get_messages(var/ckey, var/limit)
if(!ckey)
return
var/list/getdef = list("SELECT * FROM messages WHERE ckey = ? AND worldtime >= ?", ckey, oldest)
var/list/getdef
if (limit)
getdef = list("SELECT * FROM messages WHERE ckey = ? ORDER BY id DESC LIMIT [text2num(limit)]", ckey)
else
getdef = list("SELECT * FROM messages WHERE ckey = ?", ckey)
return vchat_exec_query(getdef)