NewString() публичный статический Метод

Like ED_NewString but returns string id (string_t)
public static NewString ( string s ) : int
s string
Результат int
Пример #1
0
        // Host_Name_f
        static void Name_f()
        {
            if (Cmd.Argc == 1)
            {
                Con.Print("\"name\" is \"{0}\"\n", Client.Name);
                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 (Client.Name == newName)
                {
                    return;
                }

                Cvar.Set("_cl_name", newName);
                if (Client.Cls.state == ClientActivityState.Connected)
                {
                    Cmd.ForwardToServer();
                }

                return;
            }

            if (!String.IsNullOrEmpty(Host.HostClient.name) && Host.HostClient.name != "unconnected")
            {
                if (Host.HostClient.name != newName)
                {
                    Con.Print("{0} renamed to {1}\n", Host.HostClient.name, newName);
                }
            }

            Host.HostClient.name            = newName;
            Host.HostClient.edict.v.netname = Progs.NewString(newName);

            // send notification to all clients
            MessageWriter msg = Server.sv.reliable_datagram;

            msg.WriteByte(Protocol.svc_updatename);
            msg.WriteByte(Host.ClientNum);
            msg.WriteString(newName);
        }
Пример #2
0
 static int SetTempString(string value)
 {
     if (_TempString == -1)
     {
         _TempString = Progs.NewString(value);
     }
     else
     {
         Progs.SetString(_TempString, value);
     }
     return(_TempString);
 }
Пример #3
0
        /// <summary>
        /// SV_SpawnServer
        /// </summary>
        public static void SpawnServer(string server)
        {
            // let's not have any servers with no name
            if (String.IsNullOrEmpty(Net.HostName))
            {
                Cvar.Set("hostname", "UNNAMED");
            }

            Scr.CenterTimeOff = 0;

            Con.DPrint("SpawnServer: {0}\n", server);
            svs.changelevel_issued = false;             // now safe to issue another

            //
            // tell all connected clients that we are going to a new level
            //
            if (sv.active)
            {
                SendReconnect();
            }

            //
            // make cvars consistant
            //
            if (Host.IsCoop)
            {
                Cvar.Set("deathmatch", 0);
            }

            Host.CurrentSkill = (int)(Host.Skill + 0.5);
            if (Host.CurrentSkill < 0)
            {
                Host.CurrentSkill = 0;
            }
            if (Host.CurrentSkill > 3)
            {
                Host.CurrentSkill = 3;
            }

            Cvar.Set("skill", (float)Host.CurrentSkill);

            //
            // set up the new server
            //
            Host.ClearMemory();

            sv.Clear();

            sv.name = server;

            // load progs to get entity field count
            Progs.LoadProgs();

            // allocate server memory
            sv.max_edicts = QDef.MAX_EDICTS;

            sv.edicts = new edict_t[sv.max_edicts];
            for (int i = 0; i < sv.edicts.Length; i++)
            {
                sv.edicts[i] = new edict_t();
            }

            // leave slots at start for clients only
            sv.num_edicts = svs.maxclients + 1;
            edict_t ent;

            for (int i = 0; i < svs.maxclients; i++)
            {
                ent = EdictNum(i + 1);
                svs.clients[i].edict = ent;
            }

            sv.state      = server_state_t.Loading;
            sv.paused     = false;
            sv.time       = 1.0;
            sv.modelname  = String.Format("maps/{0}.bsp", server);
            sv.worldmodel = Mod.ForName(sv.modelname, false);
            if (sv.worldmodel == null)
            {
                Con.Print("Couldn't spawn server {0}\n", sv.modelname);
                sv.active = false;
                return;
            }
            sv.models[1] = sv.worldmodel;

            //
            // clear world interaction links
            //
            ClearWorld();

            sv.sound_precache[0] = String.Empty;
            sv.model_precache[0] = String.Empty;

            sv.model_precache[1] = sv.modelname;
            for (int i = 1; i < sv.worldmodel.numsubmodels; i++)
            {
                sv.model_precache[1 + i] = _LocalModels[i];
                sv.models[i + 1]         = Mod.ForName(_LocalModels[i], false);
            }

            //
            // load the rest of the entities
            //
            ent = EdictNum(0);
            ent.Clear();
            ent.v.model = Progs.StringOffset(sv.worldmodel.name);
            if (ent.v.model == -1)
            {
                ent.v.model = Progs.NewString(sv.worldmodel.name);
            }
            ent.v.modelindex = 1;               // world model
            ent.v.solid      = Solids.SOLID_BSP;
            ent.v.movetype   = Movetypes.MOVETYPE_PUSH;

            if (Host.IsCoop)
            {
                Progs.GlobalStruct.coop = 1; //coop.value;
            }
            else
            {
                Progs.GlobalStruct.deathmatch = Host.Deathmatch;
            }

            int offset = Progs.NewString(sv.name);

            Progs.GlobalStruct.mapname = offset;

            // serverflags are for cross level information (sigils)
            Progs.GlobalStruct.serverflags = svs.serverflags;

            Progs.LoadFromFile(sv.worldmodel.entities);

            sv.active = true;

            // all setup is completed, any further precache statements are errors
            sv.state = server_state_t.Active;

            // run two frames to allow everything to settle
            Host.FrameTime = 0.1;
            Physics();
            Physics();

            // create a baseline for more efficient communications
            CreateBaseline();

            // send serverinfo to all connected clients
            for (int i = 0; i < svs.maxclients; i++)
            {
                Host.HostClient = svs.clients[i];
                if (Host.HostClient.active)
                {
                    SendServerInfo(Host.HostClient);
                }
            }

            GC.Collect();
            Con.DPrint("Server spawned.\n");
        }
Пример #4
0
        /// <summary>
        /// Host_Spawn_f
        /// </summary>
        private static void Spawn_f()
        {
            if (Cmd.Source == cmd_source_t.src_command)
            {
                Con.Print("spawn is not valid from the console\n");
                return;
            }

            if (Host.HostClient.spawned)
            {
                Con.Print("Spawn not valid -- allready spawned\n");
                return;
            }

            edict_t ent;

            // run the entrance script
            if (Server.sv.loadgame)
            {
                // loaded games are fully inited allready
                // if this is the last client to be connected, unpause
                Server.sv.paused = false;
            }
            else
            {
                // set up the edict
                ent = Host.HostClient.edict;

                ent.Clear(); //memset(&ent.v, 0, progs.entityfields * 4);
                ent.v.colormap = Server.NumForEdict(ent);
                ent.v.team     = (Host.HostClient.colors & 15) + 1;
                ent.v.netname  = Progs.NewString(Host.HostClient.name);

                // copy spawn parms out of the client_t
                Progs.GlobalStruct.SetParams(Host.HostClient.spawn_parms);

                // call the spawn function

                Progs.GlobalStruct.time = (float)Server.sv.time;
                Progs.GlobalStruct.self = Server.EdictToProg(Server.Player);
                Progs.Execute(Progs.GlobalStruct.ClientConnect);

                if ((Sys.GetFloatTime() - Host.HostClient.netconnection.connecttime) <= Server.sv.time)
                {
                    Con.DPrint("{0} entered the game\n", Host.HostClient.name);
                }

                Progs.Execute(Progs.GlobalStruct.PutClientInServer);
            }

            // send all current names, colors, and frag counts
            MsgWriter msg = Host.HostClient.message;

            msg.Clear();

            // send time of update
            msg.WriteByte(Protocol.svc_time);
            msg.WriteFloat((float)Server.sv.time);

            for (int i = 0; i < Server.svs.maxclients; i++)
            {
                client_t client = Server.svs.clients[i];
                msg.WriteByte(Protocol.svc_updatename);
                msg.WriteByte(i);
                msg.WriteString(client.name);
                msg.WriteByte(Protocol.svc_updatefrags);
                msg.WriteByte(i);
                msg.WriteShort(client.old_frags);
                msg.WriteByte(Protocol.svc_updatecolors);
                msg.WriteByte(i);
                msg.WriteByte(client.colors);
            }

            // send all current light styles
            for (int i = 0; i < QDef.MAX_LIGHTSTYLES; i++)
            {
                msg.WriteByte(Protocol.svc_lightstyle);
                msg.WriteByte((char)i);
                msg.WriteString(Server.sv.lightstyles[i]);
            }

            //
            // send some stats
            //
            msg.WriteByte(Protocol.svc_updatestat);
            msg.WriteByte(QStats.STAT_TOTALSECRETS);
            msg.WriteLong((int)Progs.GlobalStruct.total_secrets);

            msg.WriteByte(Protocol.svc_updatestat);
            msg.WriteByte(QStats.STAT_TOTALMONSTERS);
            msg.WriteLong((int)Progs.GlobalStruct.total_monsters);

            msg.WriteByte(Protocol.svc_updatestat);
            msg.WriteByte(QStats.STAT_SECRETS);
            msg.WriteLong((int)Progs.GlobalStruct.found_secrets);

            msg.WriteByte(Protocol.svc_updatestat);
            msg.WriteByte(QStats.STAT_MONSTERS);
            msg.WriteLong((int)Progs.GlobalStruct.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 = Server.EdictNum(1 + Host.ClientNum);
            msg.WriteByte(Protocol.svc_setangle);
            msg.WriteAngle(ent.v.angles.x);
            msg.WriteAngle(ent.v.angles.y);
            msg.WriteAngle(0);

            Server.WriteClientDataToMessage(Server.Player, Host.HostClient.message);

            msg.WriteByte(Protocol.svc_signonnum);
            msg.WriteByte(3);
            Host.HostClient.sendsignon = true;
        }