public static GetMessage ( |
||
sock | ||
Résultat | int |
/// <summary> /// Host_ShutdownServer /// This only happens at the end of a game, not between levels /// </summary> public static void ShutdownServer(bool crash) { if (!Server.IsActive) { return; } Server.sv.active = false; // stop all client sounds immediately if (Client.cls.state == cactive_t.ca_connected) { Client.Disconnect(); } // flush any pending messages - like the score!!! double start = Sys.GetFloatTime(); int count; do { count = 0; for (int i = 0; i < Server.svs.maxclients; i++) { HostClient = Server.svs.clients[i]; if (HostClient.active && !HostClient.message.IsEmpty) { if (Net.CanSendMessage(HostClient.netconnection)) { Net.SendMessage(HostClient.netconnection, HostClient.message); HostClient.message.Clear(); } else { Net.GetMessage(HostClient.netconnection); count++; } } } if ((Sys.GetFloatTime() - start) > 3.0) { break; } }while (count > 0); // make sure all the clients know we're disconnecting MsgWriter writer = new MsgWriter(4); writer.WriteByte(Protocol.svc_disconnect); count = Net.SendToAll(writer, 5); if (count != 0) { Con.Print("Host_ShutdownServer: NET_SendToAll failed for {0} clients\n", count); } for (int i = 0; i < Server.svs.maxclients; i++) { HostClient = Server.svs.clients[i]; if (HostClient.active) { Server.DropClient(crash); } } // // clear structures // Server.sv.Clear(); for (int i = 0; i < Server.svs.clients.Length; i++) { Server.svs.clients[i].Clear(); } }
/// <summary> /// CL_GetMessage /// Handles recording and playback of demos, on top of NET_ code /// </summary> /// <returns></returns> private static int GetMessage() { if (cls.demoplayback) { // decide if it is time to grab the next message if (cls.signon == SIGNONS) // allways grab until fully connected { if (cls.timedemo) { if (Host.FrameCount == cls.td_lastframe) { return(0); // allready read this frame's message } cls.td_lastframe = Host.FrameCount; // if this is the second frame, grab the real td_starttime // so the bogus time on the first frame doesn't count if (Host.FrameCount == cls.td_startframe + 1) { cls.td_starttime = (float)Host.RealTime; } } else if (cl.time <= cl.mtime[0]) { return(0); // don't need another message yet } } // get the next message BinaryReader reader = ((DisposableWrapper <BinaryReader>)cls.demofile).Object; int size = Common.LittleLong(reader.ReadInt32()); if (size > QDef.MAX_MSGLEN) { Sys.Error("Demo message > MAX_MSGLEN"); } cl.mviewangles[1] = cl.mviewangles[0]; cl.mviewangles[0].X = Common.LittleFloat(reader.ReadSingle()); cl.mviewangles[0].Y = Common.LittleFloat(reader.ReadSingle()); cl.mviewangles[0].Z = Common.LittleFloat(reader.ReadSingle()); Net.Message.FillFrom(reader.BaseStream, size); if (Net.Message.Length < size) { StopPlayback(); return(0); } return(1); } int r; while (true) { r = Net.GetMessage(cls.netcon); if (r != 1 && r != 2) { return(r); } // discard nop keepalive message if (Net.Message.Length == 1 && Net.Message.Data[0] == Protocol.svc_nop) { Con.Print("<-- server to client keepalive\n"); } else { break; } } if (cls.demorecording) { WriteDemoMessage(); } return(r); }
/// <summary> /// SV_ReadClientMessage /// Returns false if the client should be killed /// </summary> static bool ReadClientMessage() { while (true) { int ret = Net.GetMessage(Host.HostClient.netconnection); if (ret == -1) { Con.DPrint("SV_ReadClientMessage: NET_GetMessage failed\n"); return(false); } if (ret == 0) { return(true); } Net.Reader.Reset(); bool flag = true; while (flag) { if (!Host.HostClient.active) { return(false); // a command caused an error } if (Net.Reader.IsBadRead) { Con.DPrint("SV_ReadClientMessage: badread\n"); return(false); } int cmd = Net.Reader.ReadChar(); switch (cmd) { case -1: flag = false; // end of message ret = 1; break; case Protocol.clc_nop: break; case Protocol.clc_stringcmd: string s = Net.Reader.ReadString(); if (Host.HostClient.privileged) { ret = 2; } else { ret = 0; } if (Common.SameText(s, "status", 6)) { ret = 1; } else if (Common.SameText(s, "god", 3)) { ret = 1; } else if (Common.SameText(s, "notarget", 8)) { ret = 1; } else if (Common.SameText(s, "fly", 3)) { ret = 1; } else if (Common.SameText(s, "name", 4)) { ret = 1; } else if (Common.SameText(s, "noclip", 6)) { ret = 1; } else if (Common.SameText(s, "say", 3)) { ret = 1; } else if (Common.SameText(s, "say_team", 8)) { ret = 1; } else if (Common.SameText(s, "tell", 4)) { ret = 1; } else if (Common.SameText(s, "color", 5)) { ret = 1; } else if (Common.SameText(s, "kill", 4)) { ret = 1; } else if (Common.SameText(s, "pause", 5)) { ret = 1; } else if (Common.SameText(s, "spawn", 5)) { ret = 1; } else if (Common.SameText(s, "begin", 5)) { ret = 1; } else if (Common.SameText(s, "prespawn", 8)) { ret = 1; } else if (Common.SameText(s, "kick", 4)) { ret = 1; } else if (Common.SameText(s, "ping", 4)) { ret = 1; } else if (Common.SameText(s, "give", 4)) { ret = 1; } else if (Common.SameText(s, "ban", 3)) { ret = 1; } if (ret == 2) { Cbuf.InsertText(s); } else if (ret == 1) { Cmd.ExecuteString(s, cmd_source_t.src_client); } else { Con.DPrint("{0} tried to {1}\n", Host.HostClient.name, s); } break; case Protocol.clc_disconnect: return(false); case Protocol.clc_move: ReadClientMove(ref Host.HostClient.cmd); break; default: Con.DPrint("SV_ReadClientMessage: unknown command char\n"); return(false); } } if (ret != 1) { break; } } return(true); }