Merge branch 'SRB2-CHAT' of https://git.magicalgirl.moe/SinnamonLat/SRB2 into SRB2-CHAT

This commit is contained in:
Latapostrophe 2018-12-19 16:50:49 +01:00
commit 387173ea89
4 changed files with 66 additions and 59 deletions

View file

@ -73,7 +73,7 @@ patch_t *cred_font[CRED_FONTSIZE];
static player_t *plr; static player_t *plr;
boolean chat_on; // entering a chat message? boolean chat_on; // entering a chat message?
static char w_chat[HU_MAXMSGLEN]; static char w_chat[HU_MAXMSGLEN];
static INT32 c_input = 0; // let's try to make the chat input less shitty. static size_t c_input = 0; // let's try to make the chat input less shitty.
static boolean headsupactive = false; static boolean headsupactive = false;
boolean hu_showscores; // draw rankings boolean hu_showscores; // draw rankings
static char hu_tick; static char hu_tick;
@ -328,7 +328,7 @@ static UINT32 chat_nummsg_min = 0;
static UINT32 chat_scroll = 0; static UINT32 chat_scroll = 0;
static tic_t chat_scrolltime = 0; static tic_t chat_scrolltime = 0;
static INT32 chat_maxscroll = 0; // how far can we scroll? static UINT32 chat_maxscroll = 0; // how far can we scroll?
//static chatmsg_t chat_mini[CHAT_BUFSIZE]; // Display the last few messages sent. //static chatmsg_t chat_mini[CHAT_BUFSIZE]; // Display the last few messages sent.
//static chatmsg_t chat_log[CHAT_BUFSIZE]; // Keep every message sent to us in memory so we can scroll n shit, it's cool. //static chatmsg_t chat_log[CHAT_BUFSIZE]; // Keep every message sent to us in memory so we can scroll n shit, it's cool.
@ -346,7 +346,7 @@ static INT16 addy = 0; // use this to make the messages scroll smoothly when one
static void HU_removeChatText_Mini(void) static void HU_removeChatText_Mini(void)
{ {
// MPC: Don't create new arrays, just iterate through an existing one // MPC: Don't create new arrays, just iterate through an existing one
int i; size_t i;
for(i=0;i<chat_nummsg_min-1;i++) { for(i=0;i<chat_nummsg_min-1;i++) {
strcpy(chat_mini[i], chat_mini[i+1]); strcpy(chat_mini[i], chat_mini[i+1]);
chat_timers[i] = chat_timers[i+1]; chat_timers[i] = chat_timers[i+1];
@ -362,7 +362,7 @@ static void HU_removeChatText_Mini(void)
static void HU_removeChatText_Log(void) static void HU_removeChatText_Log(void)
{ {
// MPC: Don't create new arrays, just iterate through an existing one // MPC: Don't create new arrays, just iterate through an existing one
int i; size_t i;
for(i=0;i<chat_nummsg_log-1;i++) { for(i=0;i<chat_nummsg_log-1;i++) {
strcpy(chat_log[i], chat_log[i+1]); strcpy(chat_log[i], chat_log[i+1]);
} }
@ -456,9 +456,10 @@ static void DoSayCommand(SINT8 target, size_t usedargs, UINT8 flags)
// what we're gonna do now is check if the node exists // what we're gonna do now is check if the node exists
// with that logic, characters 4 and 5 are our numbers: // with that logic, characters 4 and 5 are our numbers:
const char *newmsg; const char *newmsg;
int spc = 1; // used if nodenum[1] is a space.
char *nodenum = (char*) malloc(3); char *nodenum = (char*) malloc(3);
strncpy(nodenum, msg+3, 5); INT32 spc = 1; // used if nodenum[1] is a space.
strncpy(nodenum, msg+3, 3);
// check for undesirable characters in our "number" // check for undesirable characters in our "number"
if (((nodenum[0] < '0') || (nodenum[0] > '9')) || ((nodenum[1] < '0') || (nodenum[1] > '9'))) if (((nodenum[0] < '0') || (nodenum[0] > '9')) || ((nodenum[1] < '0') || (nodenum[1] > '9')))
{ {
@ -595,7 +596,7 @@ static void Got_Saycmd(UINT8 **p, INT32 playernum)
char *msg; char *msg;
boolean action = false; boolean action = false;
char *ptr; char *ptr;
int spam_eatmsg = 0; INT32 spam_eatmsg = 0;
CONS_Debug(DBG_NETPLAY,"Received SAY cmd from Player %d (%s)\n", playernum+1, player_names[playernum]); CONS_Debug(DBG_NETPLAY,"Received SAY cmd from Player %d (%s)\n", playernum+1, player_names[playernum]);
@ -727,9 +728,10 @@ static void Got_Saycmd(UINT8 **p, INT32 playernum)
} }
else else
{ {
const UINT8 color = players[playernum].skincolor;
cstart = "\x83"; cstart = "\x83";
const UINT8 color = players[playernum].skincolor;
if (color <= SKINCOLOR_SILVER) if (color <= SKINCOLOR_SILVER)
cstart = "\x80"; // White cstart = "\x80"; // White
else if (color <= SKINCOLOR_BLACK) else if (color <= SKINCOLOR_BLACK)
@ -841,7 +843,7 @@ static inline boolean HU_keyInChatString(char *s, char ch)
{ {
// move everything past c_input for new characters: // move everything past c_input for new characters:
INT32 m = HU_MAXMSGLEN-1; size_t m = HU_MAXMSGLEN-1;
for (;(m>=c_input);m--) for (;(m>=c_input);m--)
{ {
if (s[m]) if (s[m])
@ -856,9 +858,11 @@ static inline boolean HU_keyInChatString(char *s, char ch)
} }
else if (ch == KEY_BACKSPACE) else if (ch == KEY_BACKSPACE)
{ {
size_t i = c_input;
if (c_input <= 0) if (c_input <= 0)
return false; return false;
size_t i = c_input;
if (!s[i-1]) if (!s[i-1])
return false; return false;
@ -910,14 +914,17 @@ static void HU_queueChatChar(char c)
if (c == KEY_ENTER) if (c == KEY_ENTER)
{ {
char buf[2+256]; char buf[2+256];
size_t ci = 2;
char *msg = &buf[2]; char *msg = &buf[2];
size_t i = 0;
size_t ci = 2;
INT32 target = 0;
do { do {
c = w_chat[-2+ci++]; c = w_chat[-2+ci++];
if (!c || (c >= ' ' && !(c & 0x80))) // copy printable characters and terminating '\0' only. if (!c || (c >= ' ' && !(c & 0x80))) // copy printable characters and terminating '\0' only.
buf[ci-1]=c; buf[ci-1]=c;
} while (c); } while (c);
size_t i = 0;
for (;(i<HU_MAXMSGLEN);i++) for (;(i<HU_MAXMSGLEN);i++)
w_chat[i] = 0; // reset this. w_chat[i] = 0; // reset this.
@ -930,10 +937,12 @@ static void HU_queueChatChar(char c)
return; return;
} }
INT32 target = 0;
if (strlen(msg) > 4 && strnicmp(msg, "/pm", 3) == 0) // used /pm if (strlen(msg) > 4 && strnicmp(msg, "/pm", 3) == 0) // used /pm
{ {
INT32 spc = 1; // used if nodenum[1] is a space.
char *nodenum = (char*) malloc(3);
const char *newmsg = msg+5+spc;
// what we're gonna do now is check if the node exists // what we're gonna do now is check if the node exists
// with that logic, characters 4 and 5 are our numbers: // with that logic, characters 4 and 5 are our numbers:
@ -944,9 +953,7 @@ static void HU_queueChatChar(char c)
return; return;
} }
int spc = 1; // used if nodenum[1] is a space. strncpy(nodenum, msg+3, 3);
char *nodenum = (char*) malloc(3);
strncpy(nodenum, msg+3, 5);
// check for undesirable characters in our "number" // check for undesirable characters in our "number"
if (((nodenum[0] < '0') || (nodenum[0] > '9')) || ((nodenum[1] < '0') || (nodenum[1] > '9'))) if (((nodenum[0] < '0') || (nodenum[0] > '9')) || ((nodenum[1] < '0') || (nodenum[1] > '9')))
{ {
@ -981,8 +988,8 @@ static void HU_queueChatChar(char c)
HU_AddChatText(va("\x82NOTICE: \x80Player %d does not exist.", target), false); // same HU_AddChatText(va("\x82NOTICE: \x80Player %d does not exist.", target), false); // same
return; return;
} }
// we need to get rid of the /pm<node> // we need to get rid of the /pm<node>
const char *newmsg = msg+5+spc;
memcpy(msg, newmsg, 255); memcpy(msg, newmsg, 255);
} }
if (ci > 3) // don't send target+flags+empty message. if (ci > 3) // don't send target+flags+empty message.
@ -1199,9 +1206,9 @@ boolean HU_Responder(event_t *ev)
// This is a muuuch better method than V_WORDWRAP. // This is a muuuch better method than V_WORDWRAP.
// again stolen and modified a bit from video.c, don't mind me, will need to rearrange this one day. // again stolen and modified a bit from video.c, don't mind me, will need to rearrange this one day.
// this one is simplified for the chat drawer. // this one is simplified for the chat drawer.
char *CHAT_WordWrap(INT32 x, INT32 w, INT32 option, const char *string) static char *CHAT_WordWrap(INT32 x, INT32 w, INT32 option, const char *string)
{ {
int c; INT32 c;
size_t chw, i, lastusablespace = 0; size_t chw, i, lastusablespace = 0;
size_t slen; size_t slen;
char *newstring = Z_StrDup(string); char *newstring = Z_StrDup(string);
@ -1628,8 +1635,8 @@ static void HU_DrawChat(void)
boolean skippedline = false; boolean skippedline = false;
if (c_input == (i+1)) if (c_input == (i+1))
{ {
int cursorx = (c+charwidth < boxw-charwidth) ? (chatx + 2 + c+charwidth) : (chatx+1); // we may have to go down. INT32 cursorx = (c+charwidth < boxw-charwidth) ? (chatx + 2 + c+charwidth) : (chatx+1); // we may have to go down.
int cursory = (cursorx != chatx+1) ? (y) : (y+charheight); INT32 cursory = (cursorx != chatx+1) ? (y) : (y+charheight);
if (hu_tick < 4) if (hu_tick < 4)
V_DrawChatCharacter(cursorx, cursory+1, '_' |V_SNAPTOBOTTOM|V_SNAPTOLEFT|t, !cv_allcaps.value, NULL); V_DrawChatCharacter(cursorx, cursory+1, '_' |V_SNAPTOBOTTOM|V_SNAPTOLEFT|t, !cv_allcaps.value, NULL);
@ -1638,7 +1645,6 @@ static void HU_DrawChat(void)
typelines += 1; typelines += 1;
skippedline = true; skippedline = true;
} }
} }
//Hurdler: isn't it better like that? //Hurdler: isn't it better like that?
@ -1686,7 +1692,7 @@ static void HU_DrawChat(void)
nodenum = (char*) malloc(3); nodenum = (char*) malloc(3);
strncpy(nodenum, w_chat+3, 4); strncpy(nodenum, w_chat+3, 3);
n = atoi((const char*) nodenum); // turn that into a number n = atoi((const char*) nodenum); // turn that into a number
// special cases: // special cases:
@ -1783,8 +1789,8 @@ static void HU_DrawChat_Old(void)
if (c_input == (i+1) && hu_tick < 4) if (c_input == (i+1) && hu_tick < 4)
{ {
int cursorx = (HU_INPUTX+c+charwidth < vid.width) ? (HU_INPUTX + c + charwidth) : (HU_INPUTX); // we may have to go down. INT32 cursorx = (HU_INPUTX+c+charwidth < vid.width) ? (HU_INPUTX + c + charwidth) : (HU_INPUTX); // we may have to go down.
int cursory = (cursorx != HU_INPUTX) ? (y) : (y+charheight); INT32 cursory = (cursorx != HU_INPUTX) ? (y) : (y+charheight);
V_DrawCharacter(cursorx, cursory+2*con_scalefactor, '_' |cv_constextsize.value | V_NOSCALESTART|t, !cv_allcaps.value); V_DrawCharacter(cursorx, cursory+2*con_scalefactor, '_' |cv_constextsize.value | V_NOSCALESTART|t, !cv_allcaps.value);
} }
@ -2158,6 +2164,8 @@ void HU_drawPing(INT32 x, INT32 y, INT32 ping, boolean notext)
UINT8 barcolor = 128; // color we use for the bars (green, yellow or red) UINT8 barcolor = 128; // color we use for the bars (green, yellow or red)
SINT8 i = 0; SINT8 i = 0;
SINT8 yoffset = 6; SINT8 yoffset = 6;
INT32 dx = x+1 - (V_SmallStringWidth(va("%dms", ping), V_ALLOWLOWERCASE)/2);
if (ping < 128) if (ping < 128)
{ {
numbars = 3; numbars = 3;
@ -2169,7 +2177,6 @@ void HU_drawPing(INT32 x, INT32 y, INT32 ping, boolean notext)
barcolor = 103; barcolor = 103;
} }
INT32 dx = x+1 - (V_SmallStringWidth(va("%dms", ping), V_ALLOWLOWERCASE)/2);
if (!notext || vid.width >= 640) // how sad, we're using a shit resolution. if (!notext || vid.width >= 640) // how sad, we're using a shit resolution.
V_DrawSmallString(dx, y+4, V_ALLOWLOWERCASE, va("%dms", ping)); V_DrawSmallString(dx, y+4, V_ALLOWLOWERCASE, va("%dms", ping));
@ -2400,6 +2407,8 @@ void HU_DrawTeamTabRankings(playersort_t *tab, INT32 whiteplayer)
INT32 i,x,y; INT32 i,x,y;
INT32 redplayers = 0, blueplayers = 0; INT32 redplayers = 0, blueplayers = 0;
boolean smol = false; boolean smol = false;
const UINT8 *colormap;
char name[MAXPLAYERNAME+1];
// before we draw, we must count how many players are in each team. It makes an additional loop, but we need to know if we have to draw a big or a small ranking. // before we draw, we must count how many players are in each team. It makes an additional loop, but we need to know if we have to draw a big or a small ranking.
for (i = 0; i < MAXPLAYERS; i++) for (i = 0; i < MAXPLAYERS; i++)
@ -2439,9 +2448,6 @@ void HU_DrawTeamTabRankings(playersort_t *tab, INT32 whiteplayer)
V_DrawFill(1, 26, 318, 1, 0); //And a horizontal line to make a T. V_DrawFill(1, 26, 318, 1, 0); //And a horizontal line to make a T.
V_DrawFill(1, 180, 318, 1, 0); //And a horizontal line near the bottom. V_DrawFill(1, 180, 318, 1, 0); //And a horizontal line near the bottom.
const UINT8 *colormap;
char name[MAXPLAYERNAME+1];
i=0, redplayers=0, blueplayers=0; i=0, redplayers=0, blueplayers=0;
for (i = 0; i < MAXPLAYERS; i++) for (i = 0; i < MAXPLAYERS; i++)
@ -2611,7 +2617,7 @@ void HU_DrawDualTabRankings(INT32 x, INT32 y, playersort_t *tab, INT32 scoreline
// //
// HU_Draw32TabRankings // HU_Draw32TabRankings
// //
void HU_Draw32TabRankings(INT32 x, INT32 y, playersort_t *tab, INT32 scorelines, INT32 whiteplayer) static void HU_Draw32TabRankings(INT32 x, INT32 y, playersort_t *tab, INT32 scorelines, INT32 whiteplayer)
{ {
INT32 i; INT32 i;
const UINT8 *colormap; const UINT8 *colormap;

View file

@ -96,9 +96,11 @@ static int lib_chatprint(lua_State *L)
{ {
const char *str = luaL_checkstring(L, 1); // retrieve string const char *str = luaL_checkstring(L, 1); // retrieve string
boolean sound = luaL_checkboolean(L, 2); // retrieve sound boolean boolean sound = luaL_checkboolean(L, 2); // retrieve sound boolean
int len = strlen(str);
if (str == NULL) // error if we don't have a string! if (str == NULL) // error if we don't have a string!
return luaL_error(L, LUA_QL("tostring") " must return a string to " LUA_QL("chatprint")); return luaL_error(L, LUA_QL("tostring") " must return a string to " LUA_QL("chatprint"));
int len = strlen(str);
if (len > 255) // string is too long!!! if (len > 255) // string is too long!!!
return luaL_error(L, "String exceeds the 255 characters limit of the chat buffer."); return luaL_error(L, "String exceeds the 255 characters limit of the chat buffer.");
@ -110,7 +112,11 @@ static int lib_chatprint(lua_State *L)
static int lib_chatprintf(lua_State *L) static int lib_chatprintf(lua_State *L)
{ {
int n = lua_gettop(L); /* number of arguments */ int n = lua_gettop(L); /* number of arguments */
const char *str = luaL_checkstring(L, 2); // retrieve string
boolean sound = luaL_checkboolean(L, 3); // sound?
int len = strlen(str);
player_t *plr; player_t *plr;
if (n < 2) if (n < 2)
return luaL_error(L, "chatprintf requires at least two arguments: player and text."); return luaL_error(L, "chatprintf requires at least two arguments: player and text.");
@ -120,11 +126,9 @@ static int lib_chatprintf(lua_State *L)
if (plr != &players[consoleplayer]) if (plr != &players[consoleplayer])
return 0; return 0;
const char *str = luaL_checkstring(L, 2); // retrieve string
boolean sound = luaL_checkboolean(L, 3); // sound?
if (str == NULL) // error if we don't have a string! if (str == NULL) // error if we don't have a string!
return luaL_error(L, LUA_QL("tostring") " must return a string to " LUA_QL("chatprintf")); return luaL_error(L, LUA_QL("tostring") " must return a string to " LUA_QL("chatprintf"));
int len = strlen(str);
if (len > 255) // string is too long!!! if (len > 255) // string is too long!!!
return luaL_error(L, "String exceeds the 255 characters limit of the chat buffer."); return luaL_error(L, "String exceeds the 255 characters limit of the chat buffer.");

View file

@ -1315,13 +1315,14 @@ static menuitem_t OP_GameOptionsMenu[] =
static menuitem_t OP_ChatOptionsMenu[] = static menuitem_t OP_ChatOptionsMenu[] =
{ {
{IT_STRING | IT_CVAR | IT_CV_SLIDER, NULL, "Chat Box Width", &cv_chatwidth, 10}, {IT_STRING | IT_CVAR, NULL, "Chat Mode", &cv_consolechat, 10},
{IT_STRING | IT_CVAR | IT_CV_SLIDER, NULL, "Chat Box Height", &cv_chatheight, 20},
{IT_STRING | IT_CVAR, NULL, "Message Fadeout Time", &cv_chattime, 30}, {IT_STRING | IT_CVAR | IT_CV_SLIDER, NULL, "Chat Box Width", &cv_chatwidth, 30},
{IT_STRING | IT_CVAR, NULL, "Chat Notifications", &cv_chatnotifications, 40}, {IT_STRING | IT_CVAR | IT_CV_SLIDER, NULL, "Chat Box Height", &cv_chatheight, 40},
{IT_STRING | IT_CVAR, NULL, "Spam Protection", &cv_chatspamprotection, 50}, {IT_STRING | IT_CVAR, NULL, "Message Fadeout Time", &cv_chattime, 50},
{IT_STRING | IT_CVAR, NULL, "Chat background tint", &cv_chatbacktint, 60}, {IT_STRING | IT_CVAR, NULL, "Chat Notifications", &cv_chatnotifications, 60},
{IT_STRING | IT_CVAR, NULL, "Chat Mode", &cv_consolechat, 70}, {IT_STRING | IT_CVAR, NULL, "Spam Protection", &cv_chatspamprotection, 70},
{IT_STRING | IT_CVAR, NULL, "Chat background tint", &cv_chatbacktint, 80},
}; };
static menuitem_t OP_ServerOptionsMenu[] = static menuitem_t OP_ServerOptionsMenu[] =

View file

@ -881,6 +881,7 @@ void V_DrawFillConsoleMap(INT32 x, INT32 y, INT32 w, INT32 h, INT32 c)
{ {
UINT8 *dest; UINT8 *dest;
INT32 u, v; INT32 u, v;
UINT8 *fadetable;
UINT32 alphalevel = 0; UINT32 alphalevel = 0;
if (rendermode == render_none) if (rendermode == render_none)
@ -965,24 +966,19 @@ void V_DrawFillConsoleMap(INT32 x, INT32 y, INT32 w, INT32 h, INT32 c)
c &= 255; c &= 255;
if (!alphalevel) { // Jimita (12-04-2018)
for (v = 0; v < h; v++, dest += vid.width) { w = min(w, vid.width);
for (u = 0; u < w; u++) { h = min(h, vid.height);
fadetable = ((UINT8 *)transtables + ((alphalevel-1)<<FF_TRANSSHIFT) + (c*256));
for (v = 0; v < h; v++, dest += vid.width)
for (u = 0; u < w; u++)
{
if (!alphalevel)
dest[u] = consolebgmap[dest[u]]; dest[u] = consolebgmap[dest[u]];
} else
}
} else { // mpc 12-04-2018
const UINT8 *fadetable = ((UINT8 *)transtables + ((alphalevel-1)<<FF_TRANSSHIFT) + (c*256));
#define clip(x,y) (x>y) ? y : x
w = clip(w,vid.width);
h = clip(h,vid.height);
for (v = 0; v < h; v++, dest += vid.width) {
for (u = 0; u < w; u++) {
dest[u] = fadetable[consolebgmap[dest[u]]]; dest[u] = fadetable[consolebgmap[dest[u]]];
} }
} }
}
}
// //
// Fills a box of pixels using a flat texture as a pattern, scaled to screen size. // Fills a box of pixels using a flat texture as a pattern, scaled to screen size.