duplicate connection fixes
git-svn-id: svn://svn.code.sf.net/p/actiongame/code/trunk/ac@2693 e016b1c5-ed68-44aa-a2f7-31cac88cffde
This commit is contained in:
+23
-6
@@ -56,9 +56,13 @@ void abortconnect()
|
||||
clientpassword[0] = '\0';
|
||||
if(connpeer->state!=ENET_PEER_STATE_DISCONNECTED) enet_peer_reset(connpeer);
|
||||
connpeer = NULL;
|
||||
if(curpeer) return;
|
||||
enet_host_destroy(clienthost);
|
||||
clienthost = NULL;
|
||||
#if 0
|
||||
if(!curpeer)
|
||||
{
|
||||
enet_host_destroy(clienthost);
|
||||
clienthost = NULL;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void connects(char *servername, char *serverport, char *password)
|
||||
@@ -114,7 +118,7 @@ void connectadmin(char *servername, char *serverport, char *password)
|
||||
{
|
||||
if(!password) return;
|
||||
connects(servername, serverport, password);
|
||||
if(clienthost) addmsg(SV_SETADMIN, "ris", 1, password); // in case the server is not private locked or pwd protected
|
||||
if(connmillis >= totalmillis) addmsg(SV_SETADMIN, "ris", 1, password); // in case the server is not private locked or pwd protected
|
||||
}
|
||||
|
||||
void lanconnect()
|
||||
@@ -157,11 +161,13 @@ void disconnect(int onlyclean, int async)
|
||||
clearworldsounds();
|
||||
localdisconnect();
|
||||
}
|
||||
#if 0
|
||||
if(!connpeer && clienthost)
|
||||
{
|
||||
enet_host_destroy(clienthost);
|
||||
clienthost = NULL;
|
||||
}
|
||||
#endif
|
||||
if(!onlyclean) localconnect();
|
||||
}
|
||||
|
||||
@@ -200,6 +206,17 @@ COMMAND(connectadmin, ARG_3STR);
|
||||
COMMAND(lanconnect, ARG_NONE);
|
||||
COMMANDN(disconnect, trydisconnect, ARG_NONE);
|
||||
|
||||
void cleanupclient()
|
||||
{
|
||||
abortconnect();
|
||||
disconnect(1);
|
||||
if(clienthost)
|
||||
{
|
||||
enet_host_destroy(clienthost);
|
||||
clienthost = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
// collect c2s messages conveniently
|
||||
|
||||
vector<uchar> messages;
|
||||
@@ -258,7 +275,7 @@ void sendpackettoserv(int chan, ENetPacket *packet)
|
||||
|
||||
void c2skeepalive()
|
||||
{
|
||||
if(clienthost) enet_host_service(clienthost, NULL, 0);
|
||||
if(clienthost && (curpeer || connpeer)) enet_host_service(clienthost, NULL, 0);
|
||||
}
|
||||
|
||||
extern string masterpwd;
|
||||
@@ -367,7 +384,7 @@ void sendintro()
|
||||
void gets2c() // get updates from the server
|
||||
{
|
||||
ENetEvent event;
|
||||
if(!clienthost) return;
|
||||
if(!clienthost || (!curpeer && !connpeer)) return;
|
||||
if(connpeer && totalmillis/3000 > connmillis/3000)
|
||||
{
|
||||
conoutf("attempting to connect...");
|
||||
|
||||
+1
-2
@@ -7,8 +7,7 @@ void cleanup(char *msg) // single program exit point;
|
||||
{
|
||||
if(!msg)
|
||||
{
|
||||
abortconnect();
|
||||
disconnect(1);
|
||||
cleanupclient();
|
||||
soundcleanup();
|
||||
cleanupserver();
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ enum { FM_PICKUP = 0, FM_DROP, FM_LOST, FM_RETURN, FM_SCORE, FM_KTFSCORE, FM_SCO
|
||||
#define DNF 100.0f
|
||||
#define DVELF 4.0f
|
||||
|
||||
enum { DISC_NONE = 0, DISC_EOP, DISC_CN, DISC_MKICK, DISC_MBAN, DISC_TAGT, DISC_BANREFUSE, DISC_WRONGPW, DISC_SOPLOGINFAIL, DISC_MAXCLIENTS, DISC_MASTERMODE, DISC_AUTOKICK, DISC_NUM };
|
||||
enum { DISC_NONE = 0, DISC_EOP, DISC_CN, DISC_MKICK, DISC_MBAN, DISC_TAGT, DISC_BANREFUSE, DISC_WRONGPW, DISC_SOPLOGINFAIL, DISC_MAXCLIENTS, DISC_MASTERMODE, DISC_AUTOKICK, DISC_DUP, DISC_NUM };
|
||||
|
||||
#define EXT_ACK -1
|
||||
#define EXT_VERSION 103
|
||||
|
||||
@@ -283,6 +283,7 @@ extern void resetwater();
|
||||
extern void connects(char *servername, char *serverport = NULL, char *password = NULL);
|
||||
extern void abortconnect();
|
||||
extern void disconnect(int onlyclean = 0, int async = 0);
|
||||
extern void cleanupclient();
|
||||
extern void toserver(char *text);
|
||||
extern void addmsg(int type, const char *fmt = NULL, ...);
|
||||
extern bool multiplayer(bool msg = true);
|
||||
|
||||
+11
-1
@@ -2019,7 +2019,7 @@ bool callvote(voteinfo *v, ENetPacket *msg) // true if a regular vote was called
|
||||
|
||||
const char *disc_reason(int reason)
|
||||
{
|
||||
static const char *disc_reasons[] = { "normal", "end of packet", "client num", "kicked by server operator", "banned by server operator", "tag type", "connection refused due to ban", "wrong password", "failed admin login", "server FULL - maxclients", "server mastermode is \"private\"", "auto kick - did your score drop below the threshold?" };
|
||||
static const char *disc_reasons[] = { "normal", "end of packet", "client num", "kicked by server operator", "banned by server operator", "tag type", "connection refused due to ban", "wrong password", "failed admin login", "server FULL - maxclients", "server mastermode is \"private\"", "auto kick - did your score drop below the threshold?", "duplicate connection" };
|
||||
return reason >= 0 && (size_t)reason < sizeof(disc_reasons)/sizeof(disc_reasons[0]) ? disc_reasons[reason] : "unknown";
|
||||
}
|
||||
|
||||
@@ -2363,6 +2363,16 @@ void process(ENetPacket *packet, int sender, int chan) // sender may be -1
|
||||
}
|
||||
if(!cl->isauthed) return;
|
||||
|
||||
if(cl->type==ST_TCPIP)
|
||||
{
|
||||
loopv(clients) if(i != sender)
|
||||
{
|
||||
client *dup = clients[i];
|
||||
if(dup->type==ST_TCPIP && dup->peer->address.host==cl->peer->address.host && dup->peer->address.port==cl->peer->address.port)
|
||||
disconnect_client(i, DISC_DUP);
|
||||
}
|
||||
}
|
||||
|
||||
ENetPacket *packet = enet_packet_create(NULL, MAXTRANS, ENET_PACKET_FLAG_RELIABLE);
|
||||
ucharbuf p(packet->data, packet->dataLength);
|
||||
welcomepacket(p, sender);
|
||||
|
||||
Reference in New Issue
Block a user