clients can now connect, but all that happens is the qtv console fills up

with "hi"
This commit is contained in:
Bill Currie 2004-02-20 05:37:47 +00:00
parent 60d2cd1ed9
commit f94b0b3800
5 changed files with 207 additions and 5 deletions

View File

@ -1,4 +1,4 @@
## Process this file with automake to produce Makefile.in
AUTOMAKE_OPTIONS= foreign
EXTRA_DIST = connection.h server.h
EXTRA_DIST = client.h connection.h server.h

47
qtv/include/client.h Normal file
View File

@ -0,0 +1,47 @@
/*
#FILENAME#
#DESCRIPTION#
Copyright (C) 2004 #AUTHOR#
Author: #AUTHOR#
Date: #DATE#
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to:
Free Software Foundation, Inc.
59 Temple Place - Suite 330
Boston, MA 02111-1307, USA
$Id$
*/
#ifndef __client_h
#define __client_h
#include "netchan.h"
typedef struct client_s {
struct info_s *userinfo;
netchan_t netchan;
} client_t;
struct connection_s;
void Client_Init (void);
void Client_Connect (struct connection_s *con, int qport, struct info_s *info);
#endif//__client_h

View File

@ -43,7 +43,7 @@ qtv_LIBS= \
$(top_builddir)/libs/console/libQFconsole.la \
$(top_builddir)/libs/util/libQFutil.la
qtv_SOURCES= connection.c qtv.c server.c
qtv_SOURCES= client.c connection.c qtv.c server.c
qtv_LDADD= $(qtv_LIBS) $(NET_LIBS) $(DL_LIBS) $(CURSES_LIBS)
qtv_LDFLAGS= $(common_ldflags)
qtv_DEPENDENCIES= $(qtv_LIBS)

82
qtv/source/client.c Normal file
View File

@ -0,0 +1,82 @@
/*
#FILENAME#
#DESCRIPTION#
Copyright (C) 2004 #AUTHOR#
Author: #AUTHOR#
Date: #DATE#
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to:
Free Software Foundation, Inc.
59 Temple Place - Suite 330
Boston, MA 02111-1307, USA
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
static __attribute__ ((unused)) const char rcsid[] =
"$Id$";
#ifdef HAVE_STRING_H
# include <string.h>
#endif
#ifdef HAVE_STRINGS_H
# include <strings.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include "QF/cmd.h"
#include "QF/console.h"
#include "QF/hash.h"
#include "QF/info.h"
#include "client.h"
#include "connection.h"
void
Client_Init (void)
{
}
static void
client_handler (void *object)
{
client_t *cl = (client_t *) object;
byte d[1];
Con_Printf ("hi\n");
Netchan_Transmit (&cl->netchan, 0, d);
}
void
Client_Connect (connection_t *con, int qport, info_t *info)
{
client_t *cl;
cl = calloc (1, sizeof (client_t));
Netchan_Setup (&cl->netchan, con->address, qport, NC_READ_QPORT);
cl->userinfo = info;
con->object = cl;
con->handler = client_handler;
Con_Printf ("client %s (%s) connected\n", Info_ValueForKey (info, "name"),
NET_AdrToString (con->address));
}

View File

@ -50,6 +50,7 @@ static __attribute__ ((unused)) const char rcsid[] =
#include "QF/cvar.h"
#include "QF/dstring.h"
#include "QF/idparse.h"
#include "QF/info.h"
#include "QF/plugin.h"
#include "QF/qargs.h"
#include "QF/quakefs.h"
@ -57,15 +58,19 @@ static __attribute__ ((unused)) const char rcsid[] =
#include "QF/va.h"
#include "QF/zone.h"
#include "client.h"
#include "compat.h"
#include "connection.h"
#include "netchan.h"
#include "server.h"
#define PORT_QTV 27501
#define A2A_PING 'k'
#define A2A_ACK 'l'
#define A2C_PRINT 'n'
#define A2A_PING 'k'
#define A2A_ACK 'l'
#define A2C_PRINT 'n'
#define S2C_CHALLENGE 'c'
#define S2C_CONNECTION 'j'
#define PROTOCOL_VERSION 28
typedef enum {
RD_NONE,
@ -78,6 +83,8 @@ static plugin_list_t server_plugin_list[] = {
SERVER_PLUGIN_LIST
};
double realtime;
cbuf_t *qtv_cbuf;
cbuf_args_t *qtv_args;
@ -207,6 +214,7 @@ qtv_net_init (void)
"udp port to use");
NET_Init (qtv_port->int_val);
Connection_Init ();
net_realtime = &realtime;
Netchan_Init ();
}
@ -288,6 +296,66 @@ qtv_status (void)
qtv_end_redirect ();
}
typedef struct {
int challenge;
double time;
} challenge_t;
static void
qtv_getchallenge (void)
{
challenge_t *ch;
connection_t *con;
if ((con = Connection_Find (&net_from))) {
if (con->handler)
return;
ch = con->object;
} else {
ch = malloc (sizeof (challenge_t));
}
ch->challenge = (rand () << 16) ^ rand ();
ch->time = Sys_DoubleTime ();
if (!con)
Connection_Add (&net_from, ch, 0);
Netchan_OutOfBandPrint (net_from, "%c%i QF", S2C_CHALLENGE, ch->challenge);
}
static void
qtv_client_connect (void)
{
info_t *userinfo;
int version, qport, challenge;
connection_t *con;
challenge_t *ch;
version = atoi (Cmd_Argv (1));
if (version != PROTOCOL_VERSION) {
Netchan_OutOfBandPrint (net_from, "%c\nServer is version %s.\n",
A2C_PRINT, QW_VERSION);
Con_Printf ("* rejected connect from version %i\n", version);
return;
}
qport = atoi (Cmd_Argv (2));
challenge = atoi (Cmd_Argv (3));
if (!(con = Connection_Find (&net_from)) || con->handler
|| (ch = con->object)->challenge != challenge) {
Netchan_OutOfBandPrint (net_from, "%c\nBad challenge.\n",
A2C_PRINT);
return;
}
free (con->object);
userinfo = Info_ParseString (Cmd_Argv (4), 0, 0);
if (!userinfo) {
Netchan_OutOfBandPrint (net_from, "%c\nInvalid userinfo string.\n",
A2C_PRINT);
return;
}
Client_Connect (con, qport, userinfo);
Netchan_OutOfBandPrint (net_from, "%c", S2C_CONNECTION);
}
static void
qtv_connectionless_packet (void)
{
@ -306,6 +374,10 @@ qtv_connectionless_packet (void)
qtv_ping ();
} else if (!strcmp (cmd, "status")) {
qtv_status ();
} else if (!strcmp (cmd, "getchallenge")) {
qtv_getchallenge ();
} else if (!strcmp (cmd, "connect")) {
qtv_client_connect ();
} else {
Con_Printf ("bad connectionless packet from %s:\n%s\n",
NET_AdrToString (net_from), str);
@ -341,6 +413,7 @@ main (int argc, const char *argv[])
Cbuf_Execute_Stack (qtv_cbuf);
Sys_CheckInput (1, net_socket);
realtime = Sys_DoubleTime ();
qtv_read_packets ();