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

@ -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.
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
_snprintf(text, sizeof(text), "%s %s", tv->hostname, s);
snprintf(text, sizeof(text), "%s %s", tv->hostname, s);
}
else
{
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
_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));
@ -366,6 +366,8 @@ static void ParsePrint(sv_t *tv, netmsg_t *m, int to, unsigned int mask)
*t = '[';
if (*t == 17)
*t = ']';
if (*t == '\a') //doh. :D
*t = ' ';
}
printf("%s", text);
}

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
#endif
#define snprintf _snprintf
#elif defined(__CYGWIN__)
#include <sys/time.h>
@ -324,7 +326,9 @@ typedef struct sv_s {
SOCKET qwdsocket; //udp + quakeworld protocols
viewer_t *viewers;
int numviewers;
oproxy_t *proxies;
int numproxies;
qboolean parsingconnectiondata; //so reject any new connects for now
@ -354,6 +358,8 @@ typedef struct sv_s {
char server[MAX_QPATH];
char master[MAX_QPATH];
qboolean nobsp;
int maxviewers;
int maxproxies;
} sv_t;
typedef struct {

View file

@ -413,6 +413,8 @@ void NewQWClient(sv_t *qtv, netadr_t *addr, char *connectmessage)
qtv->viewers = viewer;
viewer->delta_frame = -1;
qtv->numviewers++;
Info_ValueForKey(infostring, "name", viewer->name, sizeof(viewer->name));
Netchan_OutOfBandPrint(qtv->qwdsocket, *addr, "j");
@ -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");
else if (qtv->parsingconnectiondata) //connecting at this time is a bit silly.
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
NewQWClient(qtv, from, buffer);
return;
@ -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'};
void QW_FreeViewer(viewer_t *viewer)
void QW_FreeViewer(sv_t *qtv, viewer_t *viewer)
{
int i;
//note: unlink them yourself.
@ -1254,6 +1258,8 @@ void QW_FreeViewer(viewer_t *viewer)
}
free(viewer);
qtv->numviewers--;
}
void QW_UpdateUDPStuff(sv_t *qtv)
@ -1340,7 +1346,7 @@ void QW_UpdateUDPStuff(sv_t *qtv)
f = qtv->viewers;
qtv->viewers = f->next;
QW_FreeViewer(f);
QW_FreeViewer(qtv, f);
}
for (v = qtv->viewers; v; v = v->next)
@ -1351,7 +1357,7 @@ void QW_UpdateUDPStuff(sv_t *qtv)
f = v->next;
v->next = f->next;
QW_FreeViewer(f);
QW_FreeViewer(qtv, f);
}
if (v->maysend && !qtv->parsingconnectiondata) //don't send incompleate connection data.

View file

@ -172,7 +172,7 @@ void Info_SetValueForStarKey (char *s, const char *key, const char *value, int m
if (!value || !strlen(value))
return;
_snprintf (newv, sizeof(newv)-1, "\\%s\\%s", key, value);
snprintf (newv, sizeof(newv)-1, "\\%s\\%s", key, value);
newv[sizeof(newv)-1] = '\0';
if ((int)(strlen(newv) + strlen(s) + 1) > maxsize)
@ -355,7 +355,7 @@ char *Rcon_Command(sv_t *qtv, char *command, char *buffer, int sizeofbuffer, qbo
else if (!strcmp(arg[0], "option"))
{
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"))
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))
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
return "Option not recognised\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"))
{
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"))
{
@ -450,17 +454,33 @@ char *Rcon_Command(sv_t *qtv, char *command, char *buffer, int sizeofbuffer, qbo
{
int news;
int newp = atoi(arg[1]);
news = Net_MVDListen(newp);
if (news != INVALID_SOCKET)
if (!newp)
{
closesocket(qtv->listenmvd);
qtv->listenmvd = news;
qtv->tcplistenportnum = newp;
return "Opened tcp port\n";
if (qtv->listenmvd != INVALID_SOCKET)
{
closesocket(qtv->listenmvd);
qtv->listenmvd = INVALID_SOCKET;
qtv->tcplistenportnum = 0;
return "mvd port is now closed\n";
}
return "Already closed\n";
}
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"))
@ -474,22 +494,41 @@ char *Rcon_Command(sv_t *qtv, char *command, char *buffer, int sizeofbuffer, qbo
return "couldn't resolve\n";
}
else if (!strcmp(arg[0], "port"))
else if (!strcmp(arg[0], "port") || !strcmp(arg[0], "udpport"))
{
int news;
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;
closesocket(qtv->qwdsocket);
qtv->qwdsocket = news;
qtv->qwlistenportnum = newp;
return "Opened udp port\n";
if (qtv->listenmvd != INVALID_SOCKET)
{
closesocket(qtv->listenmvd);
qtv->listenmvd = INVALID_SOCKET;
qtv->tcplistenportnum = 0;
return "Closed udp port\n";
}
return "udp port was already closed\n";
}
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"))

View file

@ -264,6 +264,14 @@ void Net_FindProxies(sv_t *qtv)
if (sock == INVALID_SOCKET)
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));
memset(prox, 0, sizeof(*prox));
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;
qtv->proxies = prox;
qtv->numproxies++;
}
qboolean Net_FileProxy(sv_t *qtv, char *filename)
@ -283,6 +293,8 @@ qboolean Net_FileProxy(sv_t *qtv, char *filename)
if (!f)
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));
memset(prox, 0, sizeof(*prox));
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;
qtv->proxies = prox;
qtv->numproxies++;
return true;
}
@ -562,6 +576,7 @@ void Net_ForwardStream(sv_t *qtv, char *buffer, int length)
else
closesocket(fre->sock);
free(fre);
qtv->numproxies--;
qtv->proxies = next;
}
@ -576,6 +591,7 @@ void Net_ForwardStream(sv_t *qtv, char *buffer, int length)
else
closesocket(fre->sock);
free(fre);
qtv->numproxies--;
prox->next = next;
}
@ -710,22 +726,14 @@ void NetSleep(sv_t *tv)
#ifdef _WIN32
for (;;)
#else
if (FD_ISSET(STDIN, &socketset))
#endif
{
char buffer[8192];
char *result;
char c;
#ifdef _WIN32
if (!kbhit())
break;
else
c = getch();
#else
c = recv(STDIN, &c, 1, 0);
#endif
c = getch();
if (c == '\n' || c == '\r')
{
@ -754,10 +762,30 @@ void NetSleep(sv_t *tv)
tv->commandinput[tv->inputlength++] = c;
tv->commandinput[tv->inputlength] = '\0';
}
}
}if (FD_ISSET(STDIN, &socketset))
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)
@ -1029,6 +1057,9 @@ int main(int argc, char **argv)
qtv.listenmvd = INVALID_SOCKET;
qtv.sourcesock = INVALID_SOCKET;
qtv.maxviewers = 100;
qtv.maxproxies = 100;
line[sizeof(line)-1] = '\0';
if (argc < 2)