]> git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - cl_main.c
Convert \ to / when loading texture from Q3 shader
[xonotic/darkplaces.git] / cl_main.c
index fa2e66e515a2dfb9365ae6247e083504dc0882a2..c03ff082eed865106b5265008e07f9d613194027 100644 (file)
--- a/cl_main.c
+++ b/cl_main.c
@@ -209,6 +209,9 @@ void CL_ClearState(void)
        CL_Screen_NewMap();
 }
 
+extern cvar_t cl_topcolor;
+extern cvar_t cl_bottomcolor;
+
 void CL_SetInfo(const char *key, const char *value, qboolean send, qboolean allowstarkey, qboolean allowmodel, qboolean quiet)
 {
        int i;
@@ -255,11 +258,13 @@ void CL_SetInfo(const char *key, const char *value, qboolean send, qboolean allo
                }
                else if (!strcasecmp(key, "topcolor"))
                {
-                       // don't send anything, the combined color code will be updated manually
+                       MSG_WriteByte(&cls.netcon->message, clc_stringcmd);
+                       MSG_WriteString(&cls.netcon->message, va(vabuf, sizeof(vabuf), "color %i %i", atoi(value), cl_bottomcolor.integer));
                }
                else if (!strcasecmp(key, "bottomcolor"))
                {
-                       // don't send anything, the combined color code will be updated manually
+                       MSG_WriteByte(&cls.netcon->message, clc_stringcmd);
+                       MSG_WriteString(&cls.netcon->message, va(vabuf, sizeof(vabuf), "color %i %i", cl_topcolor.integer, atoi(value)));
                }
                else if (!strcasecmp(key, "rate"))
                {
@@ -323,6 +328,8 @@ void CL_ExpandCSQCRenderEntities(int num)
        }
 }
 
+extern cvar_t rcon_secure;
+
 /*
 =====================
 CL_Disconnect
@@ -403,11 +410,87 @@ void CL_Disconnect(void)
        SCR_ClearLoadingScreen(false);
 }
 
+/*
+==================
+CL_Reconnect_f
+
+This command causes the client to wait for the signon messages again.
+This is sent just before a server changes levels
+==================
+*/
+void CL_Reconnect_f(cmd_state_t *cmd)
+{
+       char temp[128];
+       // if not connected, reconnect to the most recent server
+       if (!cls.netcon)
+       {
+               // if we have connected to a server recently, the userinfo
+               // will still contain its IP address, so get the address...
+               InfoString_GetValue(cls.userinfo, "*ip", temp, sizeof(temp));
+               if (temp[0])
+                       CL_EstablishConnection(temp, -1);
+               else
+                       Con_Printf("Reconnect to what server?  (you have not connected to a server yet)\n");
+               return;
+       }
+       // if connected, do something based on protocol
+       if (cls.protocol == PROTOCOL_QUAKEWORLD)
+       {
+               // quakeworld can just re-login
+               if (cls.qw_downloadmemory)  // don't change when downloading
+                       return;
+
+               S_StopAllSounds();
+
+               if (cls.state == ca_connected)
+               {
+                       Con_Printf("Server is changing level...\n");
+                       MSG_WriteChar(&cls.netcon->message, qw_clc_stringcmd);
+                       MSG_WriteString(&cls.netcon->message, "new");
+               }
+       }
+       else
+       {
+               // netquake uses reconnect on level changes (silly)
+               if (Cmd_Argc(cmd) != 1)
+               {
+                       Con_Print("reconnect : wait for signon messages again\n");
+                       return;
+               }
+               if (!cls.signon)
+               {
+                       Con_Print("reconnect: no signon, ignoring reconnect\n");
+                       return;
+               }
+               cls.signon = 0;         // need new connection messages
+       }
+}
+
+/*
+=====================
+CL_Connect_f
+
+User command to connect to server
+=====================
+*/
+static void CL_Connect_f(cmd_state_t *cmd)
+{
+       if (Cmd_Argc(cmd) < 2)
+       {
+               Con_Print("connect <serveraddress> [<key> <value> ...]: connect to a multiplayer game\n");
+               return;
+       }
+       // clear the rcon password, to prevent vulnerability by stuffcmd-ing a connect command
+       if(rcon_secure.integer <= 0)
+               Cvar_SetQuick(&rcon_password, "");
+       CL_EstablishConnection(Cmd_Argv(cmd, 1), 2);
+}
+
 void CL_Disconnect_f(cmd_state_t *cmd)
 {
        CL_Disconnect ();
        if (sv.active)
-               Host_ShutdownServer ();
+               SV_Shutdown ();
 }
 
 
@@ -420,7 +503,7 @@ CL_EstablishConnection
 Host should be either "local" or a net address
 =====================
 */
-void CL_EstablishConnection(const char *host, int firstarg)
+void CL_EstablishConnection(const char *address, int firstarg)
 {
        if (cls.state == ca_dedicated)
                return;
@@ -440,7 +523,7 @@ void CL_EstablishConnection(const char *host, int firstarg)
        // make sure the client ports are open before attempting to connect
        NetConn_UpdateSockets();
 
-       if (LHNETADDRESS_FromString(&cls.connect_address, host, 26000) && (cls.connect_mysocket = NetConn_ChooseClientSocketForAddress(&cls.connect_address)))
+       if (LHNETADDRESS_FromString(&cls.connect_address, address, 26000) && (cls.connect_mysocket = NetConn_ChooseClientSocketForAddress(&cls.connect_address)))
        {
                cls.connect_trying = true;
                cls.connect_remainingtries = 3;
@@ -666,11 +749,11 @@ entity_render_t *CL_NewTempEntity(double shadertime)
        return render;
 }
 
-void CL_Effect(vec3_t org, int modelindex, int startframe, int framecount, float framerate)
+void CL_Effect(vec3_t org, dp_model_t *model, int startframe, int framecount, float framerate)
 {
        int i;
        cl_effect_t *e;
-       if (!modelindex) // sanity check
+       if (!model) // sanity check
                return;
        if (framerate < 1)
        {
@@ -688,7 +771,7 @@ void CL_Effect(vec3_t org, int modelindex, int startframe, int framecount, float
                        continue;
                e->active = true;
                VectorCopy(org, e->origin);
-               e->modelindex = modelindex;
+               e->model = model;
                e->starttime = cl.time;
                e->startframe = startframe;
                e->endframe = startframe + framecount;
@@ -1688,7 +1771,7 @@ static void CL_RelinkEffects(void)
                                }
 
                                // normal stuff
-                               entrender->model = CL_GetModelByIndex(e->modelindex);
+                               entrender->model = e->model;
                                entrender->alpha = 1;
                                VectorSet(entrender->colormod, 1, 1, 1);
                                VectorSet(entrender->glowmod, 1, 1, 1);
@@ -1955,16 +2038,6 @@ void CL_UpdateWorld(void)
        r_refdef.scene.time = cl.time;
 }
 
-// LadyHavoc: pausedemo command
-static void CL_PauseDemo_f(cmd_state_t *cmd)
-{
-       cls.demopaused = !cls.demopaused;
-       if (cls.demopaused)
-               Con_Print("Demo paused\n");
-       else
-               Con_Print("Demo unpaused\n");
-}
-
 /*
 ======================
 CL_Fog_f
@@ -2195,7 +2268,7 @@ static void CL_Locs_Save_f(cmd_state_t *cmd)
                        if (VectorCompare(loc->mins, loc->maxs))
                                break;
                if (loc)
-                       Con_Warnf("Warning: writing loc file containing a mixture of qizmo-style points and proquake-style boxes may not work in qizmo or proquake!\n");
+                       Con_Printf(CON_WARN "Warning: writing loc file containing a mixture of qizmo-style points and proquake-style boxes may not work in qizmo or proquake!\n");
        }
        for (loc = cl.locnodes;loc;loc = loc->next)
        {
@@ -2415,7 +2488,8 @@ static void CL_MeshEntities_Init(void)
                VectorSet(ent->render.render_modellight_ambient, 1, 1, 1);
                VectorSet(ent->render.render_modellight_diffuse, 0, 0, 0);
                VectorSet(ent->render.render_modellight_specular, 0, 0, 0);
-               VectorSet(ent->render.render_modellight_lightdir, 0, 0, 1);
+               VectorSet(ent->render.render_modellight_lightdir_world, 0, 0, 1);
+               VectorSet(ent->render.render_modellight_lightdir_local, 0, 0, 1); // local doesn't matter because no diffuse/specular color
                VectorSet(ent->render.render_lightmap_ambient, 0, 0, 0);
                VectorSet(ent->render.render_lightmap_diffuse, 1, 1, 1);
                VectorSet(ent->render.render_lightmap_specular, 1, 1, 1);
@@ -2591,7 +2665,7 @@ static void CL_UpdateEntityShading_Entity(entity_render_t *ent)
                ent->render_modellight_ambient[q] = a[q] * ent->colormod[q];
                ent->render_modellight_diffuse[q] = c[q] * ent->colormod[q];
                ent->render_modellight_specular[q] = c[q];
-               ent->render_modellight_lightdir[q] = dir[q];
+               ent->render_modellight_lightdir_world[q] = dir[q];
                ent->render_lightmap_ambient[q] = ent->colormod[q] * r_refdef.scene.ambientintensity;
                ent->render_lightmap_diffuse[q] = ent->colormod[q] * r_refdef.scene.lightmapintensity;
                ent->render_lightmap_specular[q] = r_refdef.scene.lightmapintensity;
@@ -2607,9 +2681,12 @@ static void CL_UpdateEntityShading_Entity(entity_render_t *ent)
                for (q = 0; q < 3; q++)
                        ent->render_rtlight_diffuse[q] = ent->render_rtlight_specular[q] = q;
 
-       if (VectorLength2(ent->render_modellight_lightdir) == 0)
-               VectorSet(ent->render_modellight_lightdir, 0, 0, 1); // have to set SOME valid vector here
-       VectorNormalize(ent->render_modellight_lightdir);
+       if (VectorLength2(ent->render_modellight_lightdir_world) == 0)
+               VectorSet(ent->render_modellight_lightdir_world, 0, 0, 1); // have to set SOME valid vector here
+       VectorNormalize(ent->render_modellight_lightdir_world);
+       // transform into local space for the entity as well
+       Matrix4x4_Transform3x3(&ent->inversematrix, ent->render_modellight_lightdir_world, ent->render_modellight_lightdir_local);
+       VectorNormalize(ent->render_modellight_lightdir_local);
 }
 
 
@@ -2682,6 +2759,8 @@ void CL_Init (void)
        //
        // register our commands
        //
+               CL_InitCommands();
+
                Cvar_RegisterVariable (&cl_upspeed);
                Cvar_RegisterVariable (&cl_forwardspeed);
                Cvar_RegisterVariable (&cl_backspeed);
@@ -2709,28 +2788,21 @@ void CL_Init (void)
                Cvar_RegisterVariable (&cl_itembobspeed);
                Cvar_RegisterVariable (&cl_itembobheight);
 
+               CL_Demo_Init();
+
                Cmd_AddCommand(CMD_CLIENT, "entities", CL_PrintEntities_f, "print information on network entities known to client");
                Cmd_AddCommand(CMD_CLIENT, "disconnect", CL_Disconnect_f, "disconnect from server (or disconnect all clients if running a server)");
-               Cmd_AddCommand(CMD_CLIENT, "record", CL_Record_f, "record a demo");
-               Cmd_AddCommand(CMD_CLIENT, "stop", CL_Stop_f, "stop recording or playing a demo");
-               Cmd_AddCommand(CMD_CLIENT, "playdemo", CL_PlayDemo_f, "watch a demo file");
-               Cmd_AddCommand(CMD_CLIENT, "timedemo", CL_TimeDemo_f, "play back a demo as fast as possible and save statistics to benchmark.log");
+               Cmd_AddCommand(CMD_CLIENT, "connect", CL_Connect_f, "connect to a server by IP address or hostname");
+               Cmd_AddCommand(CMD_CLIENT | CMD_CLIENT_FROM_SERVER, "reconnect", CL_Reconnect_f, "reconnect to the last server you were on, or resets a quakeworld connection (do not use if currently playing on a netquake server)");
 
                // Support Client-side Model Index List
                Cmd_AddCommand(CMD_CLIENT, "cl_modelindexlist", CL_ModelIndexList_f, "list information on all models in the client modelindex");
                // Support Client-side Sound Index List
                Cmd_AddCommand(CMD_CLIENT, "cl_soundindexlist", CL_SoundIndexList_f, "list all sounds in the client soundindex");
 
-               Cvar_RegisterVariable (&cl_autodemo);
-               Cvar_RegisterVariable (&cl_autodemo_nameformat);
-               Cvar_RegisterVariable (&cl_autodemo_delete);
-
                Cmd_AddCommand(CMD_CLIENT, "fog", CL_Fog_f, "set global fog parameters (density red green blue [alpha [mindist [maxdist [top [fadedepth]]]]])");
                Cmd_AddCommand(CMD_CLIENT, "fog_heighttexture", CL_Fog_HeightTexture_f, "set global fog parameters (density red green blue alpha mindist maxdist top depth textures/mapname/fogheight.tga)");
 
-               // LadyHavoc: added pausedemo
-               Cmd_AddCommand(CMD_CLIENT, "pausedemo", CL_PauseDemo_f, "pause demo playback (can also safely pause demo recording if using QUAKE, QUAKEDP or NEHAHRAMOVIE protocol, useful for making movies)");
-
                Cmd_AddCommand(CMD_CLIENT, "cl_areastats", CL_AreaStats_f, "prints statistics on entity culling during collision traces");
 
                Cvar_RegisterVariable(&r_draweffects);
@@ -2776,11 +2848,7 @@ void CL_Init (void)
                CL_MeshEntities_Init();
 
                CL_Video_Init();
-               Host_StartVideo();
 
-               // put up the loading image so the user doesn't stare at a black screen...
-               SCR_BeginLoadingPlaque(true);
-               
                #ifdef CONFIG_MENU
                Cbuf_InsertText(&cmd_client,"menu_start\n");
                #endif