private Single _LastMsg; // static float lastmsg from CL_KeepaliveMessage /// <summary> /// CL_ParseServerMessage /// </summary> private void ParseServerMessage() { // // if recording demos, copy the message out // if (Host.Cvars.ShowNet.Get <Int32>( ) == 1) { Host.Console.Print("{0} ", Host.Network.Message.Length); } else if (Host.Cvars.ShowNet.Get <Int32>( ) == 2) { Host.Console.Print("------------------\n"); } cl.onground = false; // unless the server says otherwise // // parse the message // Host.Network.Reader.Reset(); Int32 i; while (true) { if (Host.Network.Reader.IsBadRead) { Host.Error("CL_ParseServerMessage: Bad server message"); } var cmd = Host.Network.Reader.ReadByte(); if (cmd == -1) { ShowNet("END OF MESSAGE"); return; // end of message } // if the high bit of the command byte is set, it is a fast update if ((cmd & 128) != 0) { ShowNet("fast update"); ParseUpdate(cmd & 127); continue; } ShowNet(_SvcStrings[cmd]); // other commands switch (cmd) { default: Host.Error("CL_ParseServerMessage: Illegible server message\n"); break; case ProtocolDef.svc_nop: break; case ProtocolDef.svc_time: cl.mtime[1] = cl.mtime[0]; cl.mtime[0] = Host.Network.Reader.ReadFloat(); break; case ProtocolDef.svc_clientdata: i = Host.Network.Reader.ReadShort(); ParseClientData(i); break; case ProtocolDef.svc_version: i = Host.Network.Reader.ReadLong(); if (i != ProtocolDef.PROTOCOL_VERSION) { Host.Error("CL_ParseServerMessage: Server is protocol {0} instead of {1}\n", i, ProtocolDef.PROTOCOL_VERSION); } break; case ProtocolDef.svc_disconnect: Host.EndGame("Server disconnected\n"); break; case ProtocolDef.svc_print: Host.Console.Print(Host.Network.Reader.ReadString()); break; case ProtocolDef.svc_centerprint: Host.Screen.CenterPrint(Host.Network.Reader.ReadString()); break; case ProtocolDef.svc_stufftext: Host.Commands.Buffer.Append(Host.Network.Reader.ReadString()); break; case ProtocolDef.svc_damage: Host.View.ParseDamage(); break; case ProtocolDef.svc_serverinfo: ParseServerInfo(); Host.Screen.vid.recalc_refdef = true; // leave intermission full screen break; case ProtocolDef.svc_setangle: cl.viewangles.X = Host.Network.Reader.ReadAngle(); cl.viewangles.Y = Host.Network.Reader.ReadAngle(); cl.viewangles.Z = Host.Network.Reader.ReadAngle(); break; case ProtocolDef.svc_setview: cl.viewentity = Host.Network.Reader.ReadShort(); break; case ProtocolDef.svc_lightstyle: i = Host.Network.Reader.ReadByte(); if (i >= QDef.MAX_LIGHTSTYLES) { Utilities.Error("svc_lightstyle > MAX_LIGHTSTYLES"); } _LightStyle[i].map = Host.Network.Reader.ReadString(); break; case ProtocolDef.svc_sound: ParseStartSoundPacket(); break; case ProtocolDef.svc_stopsound: i = Host.Network.Reader.ReadShort(); Host.Sound.StopSound(i >> 3, i & 7); break; case ProtocolDef.svc_updatename: Host.Hud.Changed(); i = Host.Network.Reader.ReadByte(); if (i >= cl.maxclients) { Host.Error("CL_ParseServerMessage: svc_updatename > MAX_SCOREBOARD"); } cl.scores[i].name = Host.Network.Reader.ReadString(); break; case ProtocolDef.svc_updatefrags: Host.Hud.Changed(); i = Host.Network.Reader.ReadByte(); if (i >= cl.maxclients) { Host.Error("CL_ParseServerMessage: svc_updatefrags > MAX_SCOREBOARD"); } cl.scores[i].frags = Host.Network.Reader.ReadShort(); break; case ProtocolDef.svc_updatecolors: Host.Hud.Changed(); i = Host.Network.Reader.ReadByte(); if (i >= cl.maxclients) { Host.Error("CL_ParseServerMessage: svc_updatecolors > MAX_SCOREBOARD"); } cl.scores[i].colors = Host.Network.Reader.ReadByte(); NewTranslation(i); break; case ProtocolDef.svc_particle: Host.RenderContext.Particles.ParseParticleEffect(Host.Client.cl.time, Host.Network.Reader); break; case ProtocolDef.svc_spawnbaseline: i = Host.Network.Reader.ReadShort(); // must use CL_EntityNum() to force cl.num_entities up ParseBaseline(EntityNum(i)); break; case ProtocolDef.svc_spawnstatic: ParseStatic(); break; case ProtocolDef.svc_temp_entity: ParseTempEntity(); break; case ProtocolDef.svc_setpause: { cl.paused = Host.Network.Reader.ReadByte() != 0; if (cl.paused) { Host.CDAudio.Pause(); } else { Host.CDAudio.Resume(); } } break; case ProtocolDef.svc_signonnum: i = Host.Network.Reader.ReadByte(); if (i <= cls.signon) { Host.Error("Received signon {0} when at {1}", i, cls.signon); } cls.signon = i; SignonReply(); break; case ProtocolDef.svc_killedmonster: cl.stats[QStatsDef.STAT_MONSTERS]++; break; case ProtocolDef.svc_foundsecret: cl.stats[QStatsDef.STAT_SECRETS]++; break; case ProtocolDef.svc_updatestat: i = Host.Network.Reader.ReadByte(); if (i < 0 || i >= QStatsDef.MAX_CL_STATS) { Utilities.Error("svc_updatestat: {0} is invalid", i); } cl.stats[i] = Host.Network.Reader.ReadLong(); break; case ProtocolDef.svc_spawnstaticsound: ParseStaticSound(); break; case ProtocolDef.svc_cdtrack: cl.cdtrack = Host.Network.Reader.ReadByte(); cl.looptrack = Host.Network.Reader.ReadByte(); if ((cls.demoplayback || cls.demorecording) && (cls.forcetrack != -1)) { Host.CDAudio.Play(( Byte )cls.forcetrack, true); } else { Host.CDAudio.Play(( Byte )cl.cdtrack, true); } break; case ProtocolDef.svc_intermission: cl.intermission = 1; cl.completed_time = ( Int32 )cl.time; Host.Screen.vid.recalc_refdef = true; // go to full screen break; case ProtocolDef.svc_finale: cl.intermission = 2; cl.completed_time = ( Int32 )cl.time; Host.Screen.vid.recalc_refdef = true; // go to full screen Host.Screen.CenterPrint(Host.Network.Reader.ReadString()); break; case ProtocolDef.svc_cutscene: cl.intermission = 3; cl.completed_time = ( Int32 )cl.time; Host.Screen.vid.recalc_refdef = true; // go to full screen Host.Screen.CenterPrint(Host.Network.Reader.ReadString()); break; case ProtocolDef.svc_sellscreen: Host.Commands.ExecuteString("help", CommandSource.Command); break; } } }
private void MessageCommandDisconnect() { Host.EndGame("Server disconnected\n"); }
static float _LastMsg; // static float lastmsg from CL_KeepaliveMessage /// <summary> /// CL_ParseServerMessage /// </summary> static void ParseServerMessage() { // // if recording demos, copy the message out // if (_ShowNet.Value == 1) { Con.Print("{0} ", Net.Message.Length); } else if (_ShowNet.Value == 2) { Con.Print("------------------\n"); } Cl.onground = false; // unless the server says otherwise // // parse the message // Net.Reader.Reset(); int i; while (true) { if (Net.Reader.IsBadRead) { Host.Error("CL_ParseServerMessage: Bad server message"); } int cmd = Net.Reader.ReadByte(); if (cmd == -1) { ShowNet("END OF MESSAGE"); return; // end of message } // if the high bit of the command byte is set, it is a fast update if ((cmd & 128) != 0) { ShowNet("fast update"); ParseUpdate(cmd & 127); continue; } ShowNet(_SvcStrings[cmd]); // other commands switch (cmd) { default: Host.Error("CL_ParseServerMessage: Illegible server message\n"); break; case Protocol.svc_nop: break; case Protocol.svc_time: Cl.mtime[1] = Cl.mtime[0]; Cl.mtime[0] = Net.Reader.ReadFloat(); break; case Protocol.svc_clientdata: i = Net.Reader.ReadShort(); ParseClientData(i); break; case Protocol.svc_version: i = Net.Reader.ReadLong(); if (i != Protocol.PROTOCOL_VERSION) { Host.Error("CL_ParseServerMessage: Server is protocol {0} instead of {1}\n", i, Protocol.PROTOCOL_VERSION); } break; case Protocol.svc_disconnect: Host.EndGame("Server disconnected\n"); break; case Protocol.svc_print: Con.Print(Net.Reader.ReadString()); break; case Protocol.svc_centerprint: Scr.CenterPrint(Net.Reader.ReadString()); break; case Protocol.svc_stufftext: Cbuf.AddText(Net.Reader.ReadString()); break; case Protocol.svc_damage: View.ParseDamage(); break; case Protocol.svc_serverinfo: ParseServerInfo(); Scr.vid.recalc_refdef = true; // leave intermission full screen break; case Protocol.svc_setangle: Cl.viewangles.X = Net.Reader.ReadAngle(); Cl.viewangles.Y = Net.Reader.ReadAngle(); Cl.viewangles.Z = Net.Reader.ReadAngle(); break; case Protocol.svc_setview: Cl.viewentity = Net.Reader.ReadShort(); break; case Protocol.svc_lightstyle: i = Net.Reader.ReadByte(); if (i >= QDef.MAX_LIGHTSTYLES) { Sys.Error("svc_lightstyle > MAX_LIGHTSTYLES"); } _LightStyle[i].map = Net.Reader.ReadString(); break; case Protocol.svc_sound: ParseStartSoundPacket(); break; case Protocol.svc_stopsound: i = Net.Reader.ReadShort(); Sound.StopSound(i >> 3, i & 7); break; case Protocol.svc_updatename: Sbar.Changed(); i = Net.Reader.ReadByte(); if (i >= Cl.maxclients) { Host.Error("CL_ParseServerMessage: svc_updatename > MAX_SCOREBOARD"); } Cl.scores[i].name = Net.Reader.ReadString(); break; case Protocol.svc_updatefrags: Sbar.Changed(); i = Net.Reader.ReadByte(); if (i >= Cl.maxclients) { Host.Error("CL_ParseServerMessage: svc_updatefrags > MAX_SCOREBOARD"); } Cl.scores[i].frags = Net.Reader.ReadShort(); break; case Protocol.svc_updatecolors: Sbar.Changed(); i = Net.Reader.ReadByte(); if (i >= Cl.maxclients) { Host.Error("CL_ParseServerMessage: svc_updatecolors > MAX_SCOREBOARD"); } Cl.scores[i].colors = Net.Reader.ReadByte(); NewTranslation(i); break; case Protocol.svc_particle: Render.ParseParticleEffect(); break; case Protocol.svc_spawnbaseline: i = Net.Reader.ReadShort(); // must use CL_EntityNum() to force cl.num_entities up ParseBaseline(EntityNum(i)); break; case Protocol.svc_spawnstatic: ParseStatic(); break; case Protocol.svc_temp_entity: ParseTempEntity(); break; case Protocol.svc_setpause: { Cl.paused = Net.Reader.ReadByte() != 0; if (Cl.paused) { CDAudio.Pause(); } else { CDAudio.Resume(); } } break; case Protocol.svc_signonnum: i = Net.Reader.ReadByte(); if (i <= Cls.signon) { Host.Error("Received signon {0} when at {1}", i, Cls.signon); } Cls.signon = i; SignonReply(); break; case Protocol.svc_killedmonster: Cl.stats[QStats.STAT_MONSTERS]++; break; case Protocol.svc_foundsecret: Cl.stats[QStats.STAT_SECRETS]++; break; case Protocol.svc_updatestat: i = Net.Reader.ReadByte(); if (i < 0 || i >= QStats.MAX_CL_STATS) { Sys.Error("svc_updatestat: {0} is invalid", i); } Cl.stats[i] = Net.Reader.ReadLong(); break; case Protocol.svc_spawnstaticsound: ParseStaticSound(); break; case Protocol.svc_cdtrack: Cl.cdtrack = Net.Reader.ReadByte(); Cl.looptrack = Net.Reader.ReadByte(); if ((Cls.demoplayback || Cls.demorecording) && (Cls.forcetrack != -1)) { CDAudio.Play((byte)Cls.forcetrack, true); } else { CDAudio.Play((byte)Cl.cdtrack, true); } break; case Protocol.svc_intermission: Cl.intermission = 1; Cl.completed_time = (int)Cl.time; Scr.vid.recalc_refdef = true; // go to full screen break; case Protocol.svc_finale: Cl.intermission = 2; Cl.completed_time = (int)Cl.time; Scr.vid.recalc_refdef = true; // go to full screen Scr.CenterPrint(Net.Reader.ReadString()); break; case Protocol.svc_cutscene: Cl.intermission = 3; Cl.completed_time = (int)Cl.time; Scr.vid.recalc_refdef = true; // go to full screen Scr.CenterPrint(Net.Reader.ReadString()); break; case Protocol.svc_sellscreen: Cmd.ExecuteString("help", cmd_source_t.src_command); break; } } }