1
0
Fork 0
forked from fte/fteqw

Some issues fixed, linux works just the same as windows

git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@1376 fc73d0e0-1445-4013-8a0c-d673dee63da5
This commit is contained in:
Spoike 2005-09-25 20:50:57 +00:00
parent 54109b7715
commit aac5a6578c
5 changed files with 158 additions and 74 deletions

View file

@ -207,7 +207,7 @@ static void ParseServerData(sv_t *tv, netmsg_t *m, int to, unsigned int playerma
{ {
int protocol; int protocol;
viewer_t *v; viewer_t *v;
protocol = ReadLong(m); protocol = ReadLong(m);
if (protocol != PROTOCOL_VERSION) if (protocol != PROTOCOL_VERSION)
{ {
@ -306,14 +306,14 @@ static void ParseStufftext(sv_t *tv, netmsg_t *m, int to, unsigned int mask)
{ //the fromproxy check is because it's fairly common to find a qw server with brackets after it's name. { //the fromproxy check is because it's fairly common to find a qw server with brackets after it's name.
char *s; char *s;
s = strchr(value, '('); //so strip the parent proxy's hostname, and put our hostname first, leaving the origional server's hostname within the brackets s = strchr(value, '('); //so strip the parent proxy's hostname, and put our hostname first, leaving the origional server's hostname within the brackets
_snprintf(text, sizeof(text), "%s %s", tv->hostname, s); snprintf(text, sizeof(text), "%s %s", tv->hostname, s);
} }
else else
{ {
if (tv->file) if (tv->file)
_snprintf(text, sizeof(text), "%s (recorded from: %s)", tv->hostname, value); snprintf(text, sizeof(text), "%s (recorded from: %s)", tv->hostname, value);
else else
_snprintf(text, sizeof(text), "%s (live: %s)", tv->hostname, value); snprintf(text, sizeof(text), "%s (live: %s)", tv->hostname, value);
} }
Info_SetValueForStarKey(tv->serverinfo, "hostname", text, sizeof(tv->serverinfo)); Info_SetValueForStarKey(tv->serverinfo, "hostname", text, sizeof(tv->serverinfo));
@ -366,6 +366,8 @@ static void ParsePrint(sv_t *tv, netmsg_t *m, int to, unsigned int mask)
*t = '['; *t = '[';
if (*t == 17) if (*t == 17)
*t = ']'; *t = ']';
if (*t == '\a') //doh. :D
*t = ' ';
} }
printf("%s", text); printf("%s", text);
} }
@ -519,7 +521,7 @@ static void ParsePlayerInfo(sv_t *tv, netmsg_t *m)
tv->players[num].active = true; tv->players[num].active = true;
tv->players[num].leafcount = BSP_SphereLeafNums(tv->bsp, MAX_ENTITY_LEAFS, tv->players[num].leafs, tv->players[num].leafcount = BSP_SphereLeafNums(tv->bsp, MAX_ENTITY_LEAFS, tv->players[num].leafs,
tv->players[num].current.origin[0]/8.0f, tv->players[num].current.origin[0]/8.0f,
tv->players[num].current.origin[1]/8.0f, tv->players[num].current.origin[1]/8.0f,
tv->players[num].current.origin[2]/8.0f, 32); tv->players[num].current.origin[2]/8.0f, 32);
@ -755,23 +757,23 @@ static void ParseSound(sv_t *tv, netmsg_t *m, int to, unsigned int mask)
unsigned char sound_num; unsigned char sound_num;
short org[3]; short org[3];
chan = ReadShort(m); chan = ReadShort(m);
if (chan & SND_VOLUME) if (chan & SND_VOLUME)
vol = ReadByte (m); vol = ReadByte (m);
else else
vol = DEFAULT_SOUND_PACKET_VOLUME; vol = DEFAULT_SOUND_PACKET_VOLUME;
if (chan & SND_ATTENUATION) if (chan & SND_ATTENUATION)
atten = ReadByte (m) / 64.0; atten = ReadByte (m) / 64.0;
else else
atten = DEFAULT_SOUND_PACKET_ATTENUATION; atten = DEFAULT_SOUND_PACKET_ATTENUATION;
sound_num = ReadByte (m); sound_num = ReadByte (m);
for (i=0 ; i<3 ; i++) for (i=0 ; i<3 ; i++)
org[i] = ReadShort (m); org[i] = ReadShort (m);
Multicast(tv, m->data+m->startpos, m->readpos - m->startpos, to, mask); Multicast(tv, m->data+m->startpos, m->readpos - m->startpos, to, mask);
} }
@ -983,7 +985,7 @@ void ParseMessage(sv_t *tv, char *buffer, int length, int to, int mask)
case svc_damage: case svc_damage:
ParseDamage(tv, &buf, to, mask); ParseDamage(tv, &buf, to, mask);
break; break;
case svc_spawnstatic: case svc_spawnstatic:
ParseSpawnStatic(tv, &buf, to, mask); ParseSpawnStatic(tv, &buf, to, mask);
break; break;
@ -992,7 +994,7 @@ void ParseMessage(sv_t *tv, char *buffer, int length, int to, int mask)
case svc_spawnbaseline: case svc_spawnbaseline:
ParseBaseline(tv, &buf, to, mask); ParseBaseline(tv, &buf, to, mask);
break; break;
case svc_temp_entity: case svc_temp_entity:
ParseTempEntity(tv, &buf, to, mask); ParseTempEntity(tv, &buf, to, mask);
break; break;
@ -1054,7 +1056,7 @@ void ParseMessage(sv_t *tv, char *buffer, int length, int to, int mask)
case svc_playerinfo: case svc_playerinfo:
ParsePlayerInfo(tv, &buf); ParsePlayerInfo(tv, &buf);
break; break;
//#define svc_nails 43 // [qbyte] num [48 bits] xyzpy 12 12 12 4 8 //#define svc_nails 43 // [qbyte] num [48 bits] xyzpy 12 12 12 4 8
case svc_chokecount: case svc_chokecount:
ReadByte(&buf); ReadByte(&buf);
break; break;
@ -1100,7 +1102,7 @@ void ParseMessage(sv_t *tv, char *buffer, int length, int to, int mask)
ParsePacketloss(tv, &buf, to, mask); ParsePacketloss(tv, &buf, to, mask);
break; break;
//#define svc_nails2 54 //qwe - [qbyte] num [52 bits] nxyzpy 8 12 12 12 4 8 //#define svc_nails2 54 //qwe - [qbyte] num [52 bits] nxyzpy 8 12 12 12 4 8
default: default:
buf.readpos = buf.startpos; buf.readpos = buf.startpos;

View file

@ -41,6 +41,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#pragma warning(disable: 4018) //signed/unsigned mismatch #pragma warning(disable: 4018) //signed/unsigned mismatch
#endif #endif
#define snprintf _snprintf
#elif defined(__CYGWIN__) #elif defined(__CYGWIN__)
#include <sys/time.h> #include <sys/time.h>
@ -324,7 +326,9 @@ typedef struct sv_s {
SOCKET qwdsocket; //udp + quakeworld protocols SOCKET qwdsocket; //udp + quakeworld protocols
viewer_t *viewers; viewer_t *viewers;
int numviewers;
oproxy_t *proxies; oproxy_t *proxies;
int numproxies;
qboolean parsingconnectiondata; //so reject any new connects for now qboolean parsingconnectiondata; //so reject any new connects for now
@ -354,6 +358,8 @@ typedef struct sv_s {
char server[MAX_QPATH]; char server[MAX_QPATH];
char master[MAX_QPATH]; char master[MAX_QPATH];
qboolean nobsp; qboolean nobsp;
int maxviewers;
int maxproxies;
} sv_t; } sv_t;
typedef struct { typedef struct {
@ -412,11 +418,11 @@ void ReadString(netmsg_t *b, char *string, int maxlen);
//#define svc_updatecolors 17 // [qbyte] [qbyte] [qbyte] //#define svc_updatecolors 17 // [qbyte] [qbyte] [qbyte]
//#define svc_particle 18 // [vec3] <variable> //#define svc_particle 18 // [vec3] <variable>
#define svc_damage 19 #define svc_damage 19
#define svc_spawnstatic 20 #define svc_spawnstatic 20
//#define svc_spawnstatic2 21 //#define svc_spawnstatic2 21
#define svc_spawnbaseline 22 #define svc_spawnbaseline 22
#define svc_temp_entity 23 // variable #define svc_temp_entity 23 // variable
//#define svc_setpause 24 // [qbyte] on / off //#define svc_setpause 24 // [qbyte] on / off
//#define svc_signonnum 25 // [qbyte] used for the signon sequence //#define svc_signonnum 25 // [qbyte] used for the signon sequence
@ -451,7 +457,7 @@ void ReadString(netmsg_t *b, char *string, int maxlen);
#define svc_download 41 // [short] size [size bytes] #define svc_download 41 // [short] size [size bytes]
#define svc_playerinfo 42 // variable #define svc_playerinfo 42 // variable
//#define svc_nails 43 // [qbyte] num [48 bits] xyzpy 12 12 12 4 8 //#define svc_nails 43 // [qbyte] num [48 bits] xyzpy 12 12 12 4 8
#define svc_chokecount 44 // [qbyte] packets choked #define svc_chokecount 44 // [qbyte] packets choked
#define svc_modellist 45 // [strings] #define svc_modellist 45 // [strings]
#define svc_soundlist 46 // [strings] #define svc_soundlist 46 // [strings]
@ -463,7 +469,7 @@ void ReadString(netmsg_t *b, char *string, int maxlen);
#define svc_serverinfo 52 // serverinfo #define svc_serverinfo 52 // serverinfo
#define svc_updatepl 53 // [qbyte] [qbyte] #define svc_updatepl 53 // [qbyte] [qbyte]
//#define svc_nails2 54 //qwe - [qbyte] num [52 bits] nxyzpy 8 12 12 12 4 8 //#define svc_nails2 54 //qwe - [qbyte] num [52 bits] nxyzpy 8 12 12 12 4 8

View file

@ -45,7 +45,7 @@ void ReadDeltaUsercmd (netmsg_t *m, const usercmd_t *from, usercmd_t *move)
memcpy (move, from, sizeof(*move)); memcpy (move, from, sizeof(*move));
bits = ReadByte (m); bits = ReadByte (m);
// read current angles // read current angles
if (bits & CM_ANGLE1) if (bits & CM_ANGLE1)
move->angles[0] = ReadShort (m); move->angles[0] = ReadShort (m);
@ -53,7 +53,7 @@ void ReadDeltaUsercmd (netmsg_t *m, const usercmd_t *from, usercmd_t *move)
move->angles[1] = ReadShort (m); move->angles[1] = ReadShort (m);
if (bits & CM_ANGLE3) if (bits & CM_ANGLE3)
move->angles[2] = ReadShort (m); move->angles[2] = ReadShort (m);
// read movement // read movement
if (bits & CM_FORWARD) if (bits & CM_FORWARD)
move->forwardmove = ReadShort(m); move->forwardmove = ReadShort(m);
@ -61,7 +61,7 @@ void ReadDeltaUsercmd (netmsg_t *m, const usercmd_t *from, usercmd_t *move)
move->sidemove = ReadShort(m); move->sidemove = ReadShort(m);
if (bits & CM_UP) if (bits & CM_UP)
move->upmove = ReadShort(m); move->upmove = ReadShort(m);
// read buttons // read buttons
if (bits & CM_BUTTONS) if (bits & CM_BUTTONS)
move->buttons = ReadByte (m); move->buttons = ReadByte (m);
@ -106,7 +106,7 @@ void WriteDeltaUsercmd (netmsg_t *m, const usercmd_t *from, usercmd_t *move)
WriteShort (m, move->angles[1]); WriteShort (m, move->angles[1]);
if (bits & CM_ANGLE3) if (bits & CM_ANGLE3)
WriteShort (m, move->angles[2]); WriteShort (m, move->angles[2]);
// read movement // read movement
if (bits & CM_FORWARD) if (bits & CM_FORWARD)
WriteShort(m, move->forwardmove); WriteShort(m, move->forwardmove);
@ -114,7 +114,7 @@ void WriteDeltaUsercmd (netmsg_t *m, const usercmd_t *from, usercmd_t *move)
WriteShort(m, move->sidemove); WriteShort(m, move->sidemove);
if (bits & CM_UP) if (bits & CM_UP)
WriteShort(m, move->upmove); WriteShort(m, move->upmove);
// read buttons // read buttons
if (bits & CM_BUTTONS) if (bits & CM_BUTTONS)
WriteByte (m, move->buttons); WriteByte (m, move->buttons);
@ -208,7 +208,7 @@ void SendServerData(sv_t *tv, viewer_t *viewer)
netmsg_t msg; netmsg_t msg;
char buffer[1024]; char buffer[1024];
InitNetMsg(&msg, buffer, sizeof(buffer)); InitNetMsg(&msg, buffer, sizeof(buffer));
BuildServerData(tv, &msg, false); BuildServerData(tv, &msg, false);
SendBufferToViewer(viewer, msg.data, msg.cursize, true); SendBufferToViewer(viewer, msg.data, msg.cursize, true);
@ -413,6 +413,8 @@ void NewQWClient(sv_t *qtv, netadr_t *addr, char *connectmessage)
qtv->viewers = viewer; qtv->viewers = viewer;
viewer->delta_frame = -1; viewer->delta_frame = -1;
qtv->numviewers++;
Info_ValueForKey(infostring, "name", viewer->name, sizeof(viewer->name)); Info_ValueForKey(infostring, "name", viewer->name, sizeof(viewer->name));
Netchan_OutOfBandPrint(qtv->qwdsocket, *addr, "j"); Netchan_OutOfBandPrint(qtv->qwdsocket, *addr, "j");
@ -433,7 +435,7 @@ void QTV_Rcon(sv_t *qtv, char *message, netadr_t *from)
while(*message > '\0' && *message <= ' ') while(*message > '\0' && *message <= ' ')
message++; message++;
command = strchr(message, ' '); command = strchr(message, ' ');
passlen = command-message; passlen = command-message;
if (passlen != strlen(qtv->password) || strncmp(message, qtv->password, passlen)) if (passlen != strlen(qtv->password) || strncmp(message, qtv->password, passlen))
@ -524,7 +526,7 @@ void ConnectionlessPacket(sv_t *qtv, netadr_t *from, netmsg_t *m)
ReadLong(m); ReadLong(m);
ReadString(m, buffer, sizeof(buffer)); ReadString(m, buffer, sizeof(buffer));
if (!strncmp(buffer, "rcon ", 5)) if (!strncmp(buffer, "rcon ", 5))
{ {
QTV_Rcon(qtv, buffer+5, from); QTV_Rcon(qtv, buffer+5, from);
@ -552,6 +554,8 @@ void ConnectionlessPacket(sv_t *qtv, netadr_t *from, netmsg_t *m)
Netchan_OutOfBandPrint(qtv->qwdsocket, *from, "n" "Proxy is not connected to a server\n"); Netchan_OutOfBandPrint(qtv->qwdsocket, *from, "n" "Proxy is not connected to a server\n");
else if (qtv->parsingconnectiondata) //connecting at this time is a bit silly. else if (qtv->parsingconnectiondata) //connecting at this time is a bit silly.
Netchan_OutOfBandPrint(qtv->qwdsocket, *from, "n" "Buffering demo, please try again\n"); Netchan_OutOfBandPrint(qtv->qwdsocket, *from, "n" "Buffering demo, please try again\n");
else if (qtv->numviewers >= qtv->maxviewers && qtv->maxviewers)
Netchan_OutOfBandPrint(qtv->qwdsocket, *from, "n" "Sorry, proxy is full.\n");
else else
NewQWClient(qtv, from, buffer); NewQWClient(qtv, from, buffer);
return; return;
@ -688,7 +692,7 @@ void SV_EmitPacketEntities (const sv_t *qtv, const viewer_t *v, const packet_ent
{ // this is a new entity, send it from the baseline { // this is a new entity, send it from the baseline
baseline = &qtv->entity[newnum].baseline; baseline = &qtv->entity[newnum].baseline;
//Con_Printf ("baseline %i\n", newnum); //Con_Printf ("baseline %i\n", newnum);
SV_WriteDelta (newnum, baseline, &to->ents[newindex], msg, true); SV_WriteDelta (newnum, baseline, &to->ents[newindex], msg, true);
newindex++; newindex++;
continue; continue;
@ -762,7 +766,7 @@ void SendPlayerStates(sv_t *tv, viewer_t *v, netmsg_t *msg)
{ {
BSP_SetupForPosition(tv->bsp, v->origin[0], v->origin[1], v->origin[2]); BSP_SetupForPosition(tv->bsp, v->origin[0], v->origin[1], v->origin[2]);
} }
lerp = ((tv->curtime - tv->oldpackettime)/1000.0f) / ((tv->nextpackettime - tv->oldpackettime)/1000.0f); lerp = ((tv->curtime - tv->oldpackettime)/1000.0f) / ((tv->nextpackettime - tv->oldpackettime)/1000.0f);
if (lerp < 0) if (lerp < 0)
lerp = 0; lerp = 0;
@ -944,7 +948,7 @@ void AngleVectors (short angles[3], float *forward, float *right, float *up)
{ {
float angle; float angle;
float sr, sp, sy, cr, cp, cy; float sr, sp, sy, cr, cp, cy;
angle = angles[1] * (M_PI*2 / 65535); angle = angles[1] * (M_PI*2 / 65535);
sy = sin(angle); sy = sin(angle);
cy = cos(angle); cy = cos(angle);
@ -1045,7 +1049,7 @@ void ParseQWC(sv_t *qtv, viewer_t *v, netmsg_t *m)
case clc_delta: case clc_delta:
v->delta_frame = ReadByte(m); v->delta_frame = ReadByte(m);
break; break;
case clc_stringcmd: case clc_stringcmd:
ReadString (m, buf, sizeof(buf)); ReadString (m, buf, sizeof(buf));
// printf("stringcmd: %s\n", buf); // printf("stringcmd: %s\n", buf);
@ -1206,7 +1210,7 @@ void ParseQWC(sv_t *qtv, viewer_t *v, netmsg_t *m)
{ {
printf("Client sent unknown string command: %s\n", buf); printf("Client sent unknown string command: %s\n", buf);
} }
break; break;
case clc_move: case clc_move:
@ -1235,7 +1239,7 @@ void ParseQWC(sv_t *qtv, viewer_t *v, netmsg_t *m)
} }
static const char dropcmd[] = {svc_stufftext, 'd', 'i', 's', 'c', 'o', 'n', 'n', 'e', 'c', 't', '\n', '\0'}; static const char dropcmd[] = {svc_stufftext, 'd', 'i', 's', 'c', 'o', 'n', 'n', 'e', 'c', 't', '\n', '\0'};
void QW_FreeViewer(viewer_t *viewer) void QW_FreeViewer(sv_t *qtv, viewer_t *viewer)
{ {
int i; int i;
//note: unlink them yourself. //note: unlink them yourself.
@ -1254,6 +1258,8 @@ void QW_FreeViewer(viewer_t *viewer)
} }
free(viewer); free(viewer);
qtv->numviewers--;
} }
void QW_UpdateUDPStuff(sv_t *qtv) void QW_UpdateUDPStuff(sv_t *qtv)
@ -1340,7 +1346,7 @@ void QW_UpdateUDPStuff(sv_t *qtv)
f = qtv->viewers; f = qtv->viewers;
qtv->viewers = f->next; qtv->viewers = f->next;
QW_FreeViewer(f); QW_FreeViewer(qtv, f);
} }
for (v = qtv->viewers; v; v = v->next) for (v = qtv->viewers; v; v = v->next)
@ -1351,7 +1357,7 @@ void QW_UpdateUDPStuff(sv_t *qtv)
f = v->next; f = v->next;
v->next = f->next; v->next = f->next;
QW_FreeViewer(f); QW_FreeViewer(qtv, f);
} }
if (v->maysend && !qtv->parsingconnectiondata) //don't send incompleate connection data. if (v->maysend && !qtv->parsingconnectiondata) //don't send incompleate connection data.

View file

@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details. See the GNU General Public License for more details.
@ -26,7 +26,7 @@ char *Info_ValueForKey (char *s, const char *key, char *buffer, int buffersize)
{ {
char pkey[1024]; char pkey[1024];
char *o; char *o;
if (*s == '\\') if (*s == '\\')
s++; s++;
while (1) while (1)
@ -59,7 +59,7 @@ char *Info_ValueForKey (char *s, const char *key, char *buffer, int buffersize)
return buffer; return buffer;
} }
*o++ = *s++; *o++ = *s++;
if (o+2 >= buffer+buffersize) //hrm. hackers at work.. if (o+2 >= buffer+buffersize) //hrm. hackers at work..
{ {
*buffer='\0'; *buffer='\0';
@ -172,7 +172,7 @@ void Info_SetValueForStarKey (char *s, const char *key, const char *value, int m
if (!value || !strlen(value)) if (!value || !strlen(value))
return; return;
_snprintf (newv, sizeof(newv)-1, "\\%s\\%s", key, value); snprintf (newv, sizeof(newv)-1, "\\%s\\%s", key, value);
newv[sizeof(newv)-1] = '\0'; newv[sizeof(newv)-1] = '\0';
if ((int)(strlen(newv) + strlen(s) + 1) > maxsize) if ((int)(strlen(newv) + strlen(s) + 1) > maxsize)
@ -209,13 +209,13 @@ char *COM_ParseToken (char *data, char *out, int outsize, const char *punctuatio
if (!punctuation) if (!punctuation)
punctuation = DEFAULT_PUNCTUATION; punctuation = DEFAULT_PUNCTUATION;
len = 0; len = 0;
out[0] = 0; out[0] = 0;
if (!data) if (!data)
return NULL; return NULL;
// skip whitespace // skip whitespace
skipwhite: skipwhite:
while ( (c = *data) <= ' ') while ( (c = *data) <= ' ')
@ -224,7 +224,7 @@ skipwhite:
return NULL; // end of file; return NULL; // end of file;
data++; data++;
} }
// skip // comments // skip // comments
if (c=='/') if (c=='/')
{ {
@ -243,7 +243,7 @@ skipwhite:
goto skipwhite; goto skipwhite;
} }
} }
// handle quoted strings specially // handle quoted strings specially
if (c == '\"') if (c == '\"')
@ -288,7 +288,7 @@ skipwhite:
if (strchr(punctuation, c)) if (strchr(punctuation, c))
break; break;
} while (c>32); } while (c>32);
out[len] = 0; out[len] = 0;
return data; return data;
} }
@ -355,7 +355,7 @@ char *Rcon_Command(sv_t *qtv, char *command, char *buffer, int sizeofbuffer, qbo
else if (!strcmp(arg[0], "option")) else if (!strcmp(arg[0], "option"))
{ {
if (!*arg[1]) if (!*arg[1])
return "option X Y\nWhere X is choke/late/talking/hostname/nobsp and Y is (mostly) 0/1\n"; return "option X Y\nWhere X is choke/late/talking/hostname/nobsp/master/maxviewers/maxproxies and Y is (mostly) 0/1\n";
if (!strcmp(arg[1], "choke")) if (!strcmp(arg[1], "choke"))
qtv->chokeonnotupdated = !!atoi(arg[2]); qtv->chokeonnotupdated = !!atoi(arg[2]);
@ -383,6 +383,10 @@ char *Rcon_Command(sv_t *qtv, char *command, char *buffer, int sizeofbuffer, qbo
if (NET_StringToAddr(arg[1], &addr)) if (NET_StringToAddr(arg[1], &addr))
NET_SendPacket (qtv->qwdsocket, 1, "k", addr); NET_SendPacket (qtv->qwdsocket, 1, "k", addr);
} }
else if (!strcmp(arg[1], "maxviewers"))
qtv->maxviewers = atoi(arg[2]);
else if (!strcmp(arg[1], "maxproxies"))
qtv->maxproxies = atoi(arg[2]);
else else
return "Option not recognised\n"; return "Option not recognised\n";
return "Set\n"; return "Set\n";
@ -436,7 +440,7 @@ char *Rcon_Command(sv_t *qtv, char *command, char *buffer, int sizeofbuffer, qbo
} }
else if (!strcmp(arg[0], "help")) else if (!strcmp(arg[0], "help"))
{ {
return "FTEQTV proxy\nValid commands: connect, file, status, option\n"; return "FTEQTV proxy version "VERSION"\nValid commands: connect, file, status, option, mvdport, port, reconnect\n";
} }
else if (!strcmp(arg[0], "reconnect")) else if (!strcmp(arg[0], "reconnect"))
{ {
@ -450,17 +454,33 @@ char *Rcon_Command(sv_t *qtv, char *command, char *buffer, int sizeofbuffer, qbo
{ {
int news; int news;
int newp = atoi(arg[1]); int newp = atoi(arg[1]);
news = Net_MVDListen(newp);
if (news != INVALID_SOCKET) if (!newp)
{ {
closesocket(qtv->listenmvd); if (qtv->listenmvd != INVALID_SOCKET)
qtv->listenmvd = news; {
qtv->tcplistenportnum = newp; closesocket(qtv->listenmvd);
return "Opened tcp port\n"; qtv->listenmvd = INVALID_SOCKET;
qtv->tcplistenportnum = 0;
return "mvd port is now closed\n";
}
return "Already closed\n";
} }
else else
return "Failed to open tcp port\n"; {
news = Net_MVDListen(newp);
if (news != INVALID_SOCKET)
{
closesocket(qtv->listenmvd);
qtv->listenmvd = news;
qtv->tcplistenportnum = newp;
return "Opened tcp port\n";
}
else
return "Failed to open tcp port\n";
}
} }
else if (!strcmp(arg[0], "ping")) else if (!strcmp(arg[0], "ping"))
@ -474,22 +494,41 @@ char *Rcon_Command(sv_t *qtv, char *command, char *buffer, int sizeofbuffer, qbo
return "couldn't resolve\n"; return "couldn't resolve\n";
} }
else if (!strcmp(arg[0], "port")) else if (!strcmp(arg[0], "port") || !strcmp(arg[0], "udpport"))
{ {
int news; int news;
int newp = atoi(arg[1]); int newp = atoi(arg[1]);
news = QW_InitUDPSocket(newp);
if (news != INVALID_SOCKET) if (!localcommand)
return "Changing udp port is not allowed via rcon\n";
if (!newp)
{ {
qtv->mastersendtime = qtv->curtime; if (qtv->listenmvd != INVALID_SOCKET)
closesocket(qtv->qwdsocket); {
qtv->qwdsocket = news; closesocket(qtv->listenmvd);
qtv->qwlistenportnum = newp; qtv->listenmvd = INVALID_SOCKET;
return "Opened udp port\n"; qtv->tcplistenportnum = 0;
return "Closed udp port\n";
}
return "udp port was already closed\n";
} }
else else
return "Failed to open udp port\n"; {
news = QW_InitUDPSocket(newp);
if (news != INVALID_SOCKET)
{
qtv->mastersendtime = qtv->curtime;
closesocket(qtv->qwdsocket);
qtv->qwdsocket = news;
qtv->qwlistenportnum = newp;
return "Opened udp port\n";
}
else
return "Failed to open udp port\n";
}
} }
else if (!strcmp(arg[0], "password")) else if (!strcmp(arg[0], "password"))

View file

@ -264,6 +264,14 @@ void Net_FindProxies(sv_t *qtv)
if (sock == INVALID_SOCKET) if (sock == INVALID_SOCKET)
return; return;
if (qtv->numproxies >= qtv->maxproxies && qtv->maxproxies)
{
const char buffer[] = {dem_all, 1, 'P','r','o','x','y',' ','i','s',' ','f','u','l','l','.'};
send(sock, buffer, strlen(buffer), 0);
closesocket(sock);
return;
}
prox = malloc(sizeof(*prox)); prox = malloc(sizeof(*prox));
memset(prox, 0, sizeof(*prox)); memset(prox, 0, sizeof(*prox));
prox->flushing = true; //allow the buffer overflow resumption code to send the connection info. prox->flushing = true; //allow the buffer overflow resumption code to send the connection info.
@ -272,6 +280,8 @@ void Net_FindProxies(sv_t *qtv)
prox->next = qtv->proxies; prox->next = qtv->proxies;
qtv->proxies = prox; qtv->proxies = prox;
qtv->numproxies++;
} }
qboolean Net_FileProxy(sv_t *qtv, char *filename) qboolean Net_FileProxy(sv_t *qtv, char *filename)
@ -283,6 +293,8 @@ qboolean Net_FileProxy(sv_t *qtv, char *filename)
if (!f) if (!f)
return false; return false;
//no full proxy check, this is going to be used by proxy admins, who won't want to have to raise the limit to start recording.
prox = malloc(sizeof(*prox)); prox = malloc(sizeof(*prox));
memset(prox, 0, sizeof(*prox)); memset(prox, 0, sizeof(*prox));
prox->flushing = true; //allow the buffer overflow resumption code to send the connection info. prox->flushing = true; //allow the buffer overflow resumption code to send the connection info.
@ -292,6 +304,8 @@ qboolean Net_FileProxy(sv_t *qtv, char *filename)
prox->next = qtv->proxies; prox->next = qtv->proxies;
qtv->proxies = prox; qtv->proxies = prox;
qtv->numproxies++;
return true; return true;
} }
@ -498,7 +512,7 @@ void Net_SendConnectionMVD(sv_t *qtv, oproxy_t *prox)
Prox_SendMessage(prox, msg.data, msg.cursize, dem_read, (unsigned)-1); Prox_SendMessage(prox, msg.data, msg.cursize, dem_read, (unsigned)-1);
msg.cursize = 0; msg.cursize = 0;
} }
for (prespawn = 0;prespawn >= 0;) for (prespawn = 0;prespawn >= 0;)
{ {
prespawn = SendList(qtv, prespawn, qtv->modellist, svc_modellist, &msg); prespawn = SendList(qtv, prespawn, qtv->modellist, svc_modellist, &msg);
@ -562,6 +576,7 @@ void Net_ForwardStream(sv_t *qtv, char *buffer, int length)
else else
closesocket(fre->sock); closesocket(fre->sock);
free(fre); free(fre);
qtv->numproxies--;
qtv->proxies = next; qtv->proxies = next;
} }
@ -576,6 +591,7 @@ void Net_ForwardStream(sv_t *qtv, char *buffer, int length)
else else
closesocket(fre->sock); closesocket(fre->sock);
free(fre); free(fre);
qtv->numproxies--;
prox->next = next; prox->next = next;
} }
@ -595,7 +611,7 @@ void Net_ForwardStream(sv_t *qtv, char *buffer, int length)
if (prox->drop) if (prox->drop)
continue; continue;
//add the new data //add the new data
Net_ProxySend(prox, buffer, length); Net_ProxySend(prox, buffer, length);
@ -710,22 +726,14 @@ void NetSleep(sv_t *tv)
#ifdef _WIN32 #ifdef _WIN32
for (;;) for (;;)
#else
if (FD_ISSET(STDIN, &socketset))
#endif
{ {
char buffer[8192]; char buffer[8192];
char *result; char *result;
char c; char c;
#ifdef _WIN32
if (!kbhit()) if (!kbhit())
break; break;
else c = getch();
c = getch();
#else
c = recv(STDIN, &c, 1, 0);
#endif
if (c == '\n' || c == '\r') if (c == '\n' || c == '\r')
{ {
@ -754,10 +762,30 @@ void NetSleep(sv_t *tv)
tv->commandinput[tv->inputlength++] = c; tv->commandinput[tv->inputlength++] = c;
tv->commandinput[tv->inputlength] = '\0'; tv->commandinput[tv->inputlength] = '\0';
} }
} }if (FD_ISSET(STDIN, &socketset))
printf("\r%s \b", tv->commandinput); printf("\r%s \b", tv->commandinput);
} }
#else
if (FD_ISSET(STDIN, &socketset))
{
char buffer[8192];
char *result;
tv->inputlength = read (0, tv->commandinput, sizeof(tv->commandinput));
if (tv->inputlength >= 1)
{
tv->commandinput[tv->inputlength-1] = 0; // rip off the /n and terminate
if (tv->inputlength)
{
tv->commandinput[tv->inputlength] = '\0';
result = Rcon_Command(tv, tv->commandinput, buffer, sizeof(buffer), true);
printf("%s", result);
tv->inputlength = 0;
tv->commandinput[0] = '\0';
}
}
}
#endif
} }
void Trim(char *s) void Trim(char *s)
@ -1029,6 +1057,9 @@ int main(int argc, char **argv)
qtv.listenmvd = INVALID_SOCKET; qtv.listenmvd = INVALID_SOCKET;
qtv.sourcesock = INVALID_SOCKET; qtv.sourcesock = INVALID_SOCKET;
qtv.maxviewers = 100;
qtv.maxproxies = 100;
line[sizeof(line)-1] = '\0'; line[sizeof(line)-1] = '\0';
if (argc < 2) if (argc < 2)