team chat

git-svn-id: svn://svn.code.sf.net/p/actiongame/code/trunk/ac@899 e016b1c5-ed68-44aa-a2f7-31cac88cffde
This commit is contained in:
driAn
2007-04-02 23:47:45 +00:00
parent cb006dec8e
commit c4cf085a10
7 changed files with 41 additions and 7 deletions
+8 -1
View File
@@ -221,7 +221,14 @@ void trydisconnect()
disconnect(0, !discmillis);
}
void toserver(char *text) { conoutf("%s:\f0 %s", player1->name, text); addmsg(SV_TEXT, "rs", text); }
void toserver(char *text)
{
bool toteam = text && text[0] == '%';
if(toteam) text++;
conoutf("%s:\f%i %s", player1->name, toteam, text);
addmsg(toteam ? SV_TEAMTEXT : SV_TEXT, "rs", text);
}
void echo(char *text) { conoutf("%s", text); }
COMMAND(echo, ARG_VARI);
+8 -2
View File
@@ -132,11 +132,17 @@ void parsemessages(int cn, playerent *d, ucharbuf &p)
case SV_SOUND:
playsound(getint(p), d ? &d->o : NULL);
break;
case SV_TEAMTEXT:
getstring(text, p);
conoutf(text);
break;
case SV_TEXT:
if(!d) return;
getstring(text, p);
conoutf("%s:\f0 %s", d->name, &text);
conoutf("%s:\f0 %s", d->name, &text);
break;
case SV_MAPCHANGE:
+1 -1
View File
@@ -46,7 +46,7 @@ void conoutf(const char *s, ...)
puts(sf);
s = sf;
int n = 0, visible;
while((visible = text_visible(s, VIRTW*4/3 - FONTH))) // cut strings to fit on screen
while((visible = text_visible(s, (VIRTW-VIRTH/6-10-FONTH)*2))) // cut strings to fit on screen
{
const char *newline = (const char *)memchr(s, '\n', visible);
if(newline) visible = newline+1-s;
+1 -1
View File
@@ -9,7 +9,7 @@
// network messages codes, c2s, c2c, s2c
enum
{
SV_INITS2C = 0, SV_INITC2S, SV_POS, SV_TEXT, SV_SOUND, SV_CDIS,
SV_INITS2C = 0, SV_INITC2S, SV_POS, SV_TEXT, SV_TEAMTEXT, SV_SOUND, SV_CDIS,
SV_GIBDIED, SV_DIED, SV_GIBDAMAGE, SV_DAMAGE, SV_SHOT, SV_FRAGS, SV_RESUME,
SV_TIMEUP, SV_EDITENT, SV_MAPRELOAD, SV_ITEMACC,
SV_MAPCHANGE, SV_ITEMSPAWN, SV_ITEMPICKUP, SV_DENIED,
+1 -1
View File
@@ -206,7 +206,7 @@ void draw_text(const char *str, int left, int top)
switch(str[i+1])
{
case '0': glColor3ub(64, 255, 128); i++; continue; // green: player talk
case '1': glColor3ub(96, 160, 255); i++; continue; // blue: "echo" command
case '1': glColor3ub(96, 160, 255); i++; continue; // blue: team chat
case '2': glColor3ub(255, 192, 64); i++; continue; // yellow: gameplay action messages, only actions done by players
case '3': glColor3ub(255, 64, 64); i++; continue; // red: important errors
case '4': glColor3ub(128, 128, 128); i++; continue; // gray
+21
View File
@@ -371,6 +371,22 @@ void ctfreset()
}
}
void sendteamtext(char *text, int sender)
{
ENetPacket *packet = enet_packet_create(NULL, MAXTRANS, ENET_PACKET_FLAG_RELIABLE);
ucharbuf p(packet->data, packet->dataLength);
putint(p, SV_TEAMTEXT);
s_sprintfd(msg)("%s:\f1%s", clients[sender]->name, text);
sendstring(msg, p);
enet_packet_resize(packet, p.length());
loopv(clients)
{
if(i==sender) continue;
if(!strcmp(clients[i]->team, clients[sender]->team)) sendpacket(i, 1, packet);
}
if(packet->referenceCount==0) enet_packet_destroy(packet);
}
char *disc_reasons[] = { "normal", "end of packet", "client num", "kicked by master", "banned by master", "tag type", "connection refused due to ban", "wrong password", "failed master login", "server FULL - maxclients", "server mastermode is \"private\"" };
void disconnect_client(int n, int reason = -1)
@@ -675,6 +691,11 @@ void process(ENetPacket *packet, int sender, int chan) // sender may be -1
getstring(text, p);
break;
case SV_TEAMTEXT:
getstring(text, p);
sendteamtext(text, sender);
break;
case SV_TEXT:
getstring(text, p);
QUEUE_MSG;
+1 -1
View File
@@ -85,7 +85,7 @@ const char *modestr(int n) { return (n>=0 && (size_t)n < sizeof(modenames)/sizeo
char msgsizesl[] = // size inclusive message token, 0 for variable or not-checked sizes
{
SV_INITS2C, 5, SV_INITC2S, 0, SV_POS, 0, SV_TEXT, 0, SV_SOUND, 2, SV_CDIS, 2,
SV_INITS2C, 5, SV_INITC2S, 0, SV_POS, 0, SV_TEXT, 0, SV_TEAMTEXT, 0, SV_SOUND, 2, SV_CDIS, 2,
SV_GIBDIED, 2, SV_DIED, 2, SV_GIBDAMAGE, 4, SV_DAMAGE, 4, SV_SHOT, 9, SV_FRAGS, 2, SV_RESUME, 3,
SV_TIMEUP, 2, SV_EDITENT, 10, SV_MAPRELOAD, 2, SV_ITEMACC, 2,
SV_MAPCHANGE, 0, SV_ITEMSPAWN, 2, SV_ITEMPICKUP, 3, SV_DENIED, 2,