public static void Host_Name_f() { if (cmd_argc == 1) { Con_Printf("\"name\" is \"{0}\"\n", cl_name.@string); return; } string newName; if (cmd_argc == 2) { newName = Cmd_Argv(1); } else { newName = cmd_args; } if (newName.Length > 16) { newName = newName.Remove(15); } if (cmd_source == cmd_source_t.src_command) { if (cl_name.@string == newName) { return; } Cvar.Cvar_Set("_cl_name", newName); if (cls.state == cactive_t.ca_connected) { Cmd_ForwardToServer(); } return; } if (!String.IsNullOrEmpty(host_client.name) && host_client.name != "unconnected") { if (host_client.name != newName) { Con_Printf("{0} renamed to {1}\n", host_client.name, newName); } } host_client.name = newName; host_client.edict.v.netname = ED_NewString(newName); // send notification to all clients MsgWriter msg = sv.reliable_datagram; msg.MSG_WriteByte(q_shared.svc_updatename); msg.MSG_WriteByte(ClientNum); msg.MSG_WriteString(newName); }
public static void SV_SendReconnect() { MsgWriter msg = new MsgWriter(128); msg.MSG_WriteChar(q_shared.svc_stufftext); msg.MSG_WriteString("reconnect\n"); NET_SendToAll(msg, 5); if (cls.state != cactive_t.ca_dedicated) { Cmd_ExecuteString("reconnect\n", cmd_source_t.src_command); } }
public static void SV_BroadcastPrint(string fmt, params object[] args) { string tmp = args.Length > 0 ? String.Format(fmt, args) : fmt; for (int i = 0; i < svs.maxclients; i++) { if (svs.clients[i].active && svs.clients[i].spawned) { MsgWriter msg = svs.clients[i].message; msg.MSG_WriteByte(q_shared.svc_print); msg.MSG_WriteString(tmp); } } }
public static void Host_Spawn_f() { if (cmd_source == cmd_source_t.src_command) { Con_Printf("spawn is not valid from the console\n"); return; } if (host_client.spawned) { Con_Printf("Spawn not valid -- allready spawned\n"); return; } edict_t ent; // run the entrance script if (sv.loadgame) { // loaded games are fully inited allready // if this is the last client to be connected, unpause sv.paused = false; } else { // set up the edict ent = host_client.edict; ent.Clear(); //memset(&ent.v, 0, progs.entityfields * 4); ent.v.colormap = NUM_FOR_EDICT(ent); ent.v.team = (host_client.colors & 15) + 1; ent.v.netname = ED_NewString(host_client.name); // copy spawn parms out of the client_t pr_global_struct.SetParams(host_client.spawn_parms); // call the spawn function pr_global_struct.time = (float)sv.time; pr_global_struct.self = EDICT_TO_PROG(sv_player); PR_ExecuteProgram(pr_global_struct.ClientConnect); if ((Sys_FloatTime() - host_client.netconnection.connecttime) <= sv.time) { Con_DPrintf("{0} entered the game\n", host_client.name); } PR_ExecuteProgram(pr_global_struct.PutClientInServer); } // send all current names, colors, and frag counts MsgWriter msg = host_client.message; msg.Clear(); // send time of update msg.MSG_WriteByte(q_shared.svc_time); msg.MSG_WriteFloat((float)sv.time); for (int i = 0; i < svs.maxclients; i++) { client_t client = svs.clients[i]; msg.MSG_WriteByte(q_shared.svc_updatename); msg.MSG_WriteByte(i); msg.MSG_WriteString(client.name); msg.MSG_WriteByte(q_shared.svc_updatefrags); msg.MSG_WriteByte(i); msg.MSG_WriteShort(client.old_frags); msg.MSG_WriteByte(q_shared.svc_updatecolors); msg.MSG_WriteByte(i); msg.MSG_WriteByte(client.colors); } // send all current light styles for (int i = 0; i < q_shared.MAX_LIGHTSTYLES; i++) { msg.MSG_WriteByte(q_shared.svc_lightstyle); msg.MSG_WriteByte((char)i); msg.MSG_WriteString(sv.lightstyles[i]); } // // send some stats // msg.MSG_WriteByte(q_shared.svc_updatestat); msg.MSG_WriteByte(q_shared.STAT_TOTALSECRETS); msg.MSG_WriteLong((int)pr_global_struct.total_secrets); msg.MSG_WriteByte(q_shared.svc_updatestat); msg.MSG_WriteByte(q_shared.STAT_TOTALMONSTERS); msg.MSG_WriteLong((int)pr_global_struct.total_monsters); msg.MSG_WriteByte(q_shared.svc_updatestat); msg.MSG_WriteByte(q_shared.STAT_SECRETS); msg.MSG_WriteLong((int)pr_global_struct.found_secrets); msg.MSG_WriteByte(q_shared.svc_updatestat); msg.MSG_WriteByte(q_shared.STAT_MONSTERS); msg.MSG_WriteLong((int)pr_global_struct.killed_monsters); // // send a fixangle // Never send a roll angle, because savegames can catch the server // in a state where it is expecting the client to correct the angle // and it won't happen if the game was just loaded, so you wind up // with a permanent head tilt ent = EDICT_NUM(1 + ClientNum); msg.MSG_WriteByte(q_shared.svc_setangle); msg.MSG_WriteAngle(ent.v.angles.x); msg.MSG_WriteAngle(ent.v.angles.y); msg.MSG_WriteAngle(0); SV_WriteClientdataToMessage(sv_player, host_client.message); msg.MSG_WriteByte(q_shared.svc_signonnum); msg.MSG_WriteByte(3); host_client.sendsignon = true; }
public static void SV_SendServerinfo(client_t client) { MsgWriter writer = client.message; writer.MSG_WriteByte(q_shared.svc_print); writer.MSG_WriteString(String.Format("{0}\nVERSION {1,4:F2} SERVER ({2} CRC)", (char)2, q_shared.VERSION, pr_crc)); writer.MSG_WriteByte(q_shared.svc_serverinfo); writer.MSG_WriteLong(q_shared.PROTOCOL_VERSION); writer.MSG_WriteByte(svs.maxclients); if (!(coop.value != 0) && deathmatch.value != 0) { writer.MSG_WriteByte(q_shared.GAME_DEATHMATCH); } else { writer.MSG_WriteByte(q_shared.GAME_COOP); } string message = GetString(sv.edicts[0].v.message); writer.MSG_WriteString(message); for (int i = 1; i < sv.model_precache.Length; i++) { string tmp = sv.model_precache[i]; if (String.IsNullOrEmpty(tmp)) { break; } writer.MSG_WriteString(tmp); } writer.MSG_WriteByte(0); for (int i = 1; i < sv.sound_precache.Length; i++) { string tmp = sv.sound_precache[i]; if (tmp == null) { break; } writer.MSG_WriteString(tmp); } writer.MSG_WriteByte(0); // send music writer.MSG_WriteByte(q_shared.svc_cdtrack); writer.MSG_WriteByte((int)sv.edicts[0].v.sounds); writer.MSG_WriteByte((int)sv.edicts[0].v.sounds); // set view writer.MSG_WriteByte(q_shared.svc_setview); writer.MSG_WriteShort(NUM_FOR_EDICT(client.edict)); writer.MSG_WriteByte(q_shared.svc_signonnum); writer.MSG_WriteByte(1); client.sendsignon = true; client.spawned = false; // need prespawn, spawn, etc }