X-Git-Url: https://git.xonotic.org/?a=blobdiff_plain;f=cl_main.c;h=e4d56733a18ba40c7f93b5ce241f1d1e35b2b46f;hb=0706fdfa8e33548670e59234409eac2c51849631;hp=c55c543e3537e2d48470b840016e3148f56c5564;hpb=9836f5e5029a2988f799e80db7cfeb4fb8224be0;p=xonotic%2Fdarkplaces.git diff --git a/cl_main.c b/cl_main.c index c55c543e..e4d56733 100644 --- a/cl_main.c +++ b/cl_main.c @@ -360,11 +360,25 @@ Sends a disconnect message to the server This is also called on Host_Error, so it shouldn't cause any errors ===================== */ -void CL_Disconnect(void) +void CL_Disconnect(qbool kicked, const char *fmt, ... ) { + va_list argptr; + char reason[512]; + if (cls.state == ca_dedicated) return; + if(fmt) + { + va_start(argptr,fmt); + dpvsnprintf(reason,sizeof(reason),fmt,argptr); + va_end(argptr); + } + else + { + dpsnprintf(reason, sizeof(reason), "Disconnect by user"); + } + if (Sys_CheckParm("-profilegameonly")) Sys_AllowProfiling(false); @@ -395,32 +409,41 @@ void CL_Disconnect(void) else if (cls.netcon) { sizebuf_t buf; - unsigned char bufdata[8]; + unsigned char bufdata[520]; if (cls.demorecording) - CL_Stop_f(cmd_client); + CL_Stop_f(cmd_local); - // send disconnect message 3 times to improve chances of server - // receiving it (but it still fails sometimes) - memset(&buf, 0, sizeof(buf)); - buf.data = bufdata; - buf.maxsize = sizeof(bufdata); - if (cls.protocol == PROTOCOL_QUAKEWORLD) + if(!kicked) { - Con_DPrint("Sending drop command\n"); - MSG_WriteByte(&buf, qw_clc_stringcmd); - MSG_WriteString(&buf, "drop"); - } - else - { - Con_DPrint("Sending clc_disconnect\n"); - MSG_WriteByte(&buf, clc_disconnect); + // send disconnect message 3 times to improve chances of server + // receiving it (but it still fails sometimes) + memset(&buf, 0, sizeof(buf)); + buf.data = bufdata; + buf.maxsize = sizeof(bufdata); + if (cls.protocol == PROTOCOL_QUAKEWORLD) + { + Con_DPrint("Sending drop command\n"); + MSG_WriteByte(&buf, qw_clc_stringcmd); + MSG_WriteString(&buf, "drop"); + } + else + { + Con_DPrint("Sending clc_disconnect\n"); + MSG_WriteByte(&buf, clc_disconnect); + if(cls.protocol == PROTOCOL_DARKPLACES8) + MSG_WriteString(&buf, reason); + } + NetConn_SendUnreliableMessage(cls.netcon, &buf, cls.protocol, 10000, 0, false); + NetConn_SendUnreliableMessage(cls.netcon, &buf, cls.protocol, 10000, 0, false); + NetConn_SendUnreliableMessage(cls.netcon, &buf, cls.protocol, 10000, 0, false); } - NetConn_SendUnreliableMessage(cls.netcon, &buf, cls.protocol, 10000, 0, false); - NetConn_SendUnreliableMessage(cls.netcon, &buf, cls.protocol, 10000, 0, false); - NetConn_SendUnreliableMessage(cls.netcon, &buf, cls.protocol, 10000, 0, false); + NetConn_Close(cls.netcon); cls.netcon = NULL; - Con_Printf("Disconnected\n"); + if(fmt) + Con_Printf("Disconnect: %s\n", reason); + else + Con_Printf("Disconnected\n"); } cls.state = ca_disconnected; cl.islocalgame = false; @@ -432,6 +455,9 @@ void CL_Disconnect(void) // If we're dropped mid-connection attempt, it won't clear otherwise. SCR_ClearLoadingScreen(false); + + if(host.hook.SV_Shutdown) + host.hook.SV_Shutdown(); } /* @@ -512,9 +538,7 @@ static void CL_Connect_f(cmd_state_t *cmd) void CL_Disconnect_f(cmd_state_t *cmd) { - CL_Disconnect (); - if (sv.active) - SV_Shutdown (); + CL_Disconnect(false, Cmd_Argc(cmd) > 1 ? Cmd_Argv(cmd, 1) : NULL); } @@ -555,8 +579,8 @@ void CL_EstablishConnection(const char *address, int firstarg) { int i; *cls.connect_userinfo = 0; - for(i = firstarg; i+2 <= Cmd_Argc(cmd_client); i += 2) - InfoString_SetValue(cls.connect_userinfo, sizeof(cls.connect_userinfo), Cmd_Argv(cmd_client, i), Cmd_Argv(cmd_client, i+1)); + for(i = firstarg; i+2 <= Cmd_Argc(cmd_local); i += 2) + InfoString_SetValue(cls.connect_userinfo, sizeof(cls.connect_userinfo), Cmd_Argv(cmd_local, i), Cmd_Argv(cmd_local, i+1)); } else if(firstarg < -1) { @@ -2492,6 +2516,7 @@ static void CL_MeshEntities_Restart(void) for (i = 0; i < NUM_MESHENTITIES; i++) { ent = cl_meshentities + i; + Mod_Mesh_Destroy(ent->render.model); Mod_Mesh_Create(ent->render.model, cl_meshentitynames[i]); } } @@ -2907,7 +2932,7 @@ void CL_Shutdown (void) S_StopAllSounds(); // disconnect client from server if active - CL_Disconnect(); + CL_Disconnect(false, NULL); CL_Video_Shutdown();