Ejemplo n.º 1
0
bool installtex(int tnum, char *texname, int &xs, int &ys, bool clamp)
{
    SDL_Surface *s = IMG_Load(texname);
    if(!s) { conoutf("couldn't load texture %s", texname); return false; };
    if(s->format->BitsPerPixel!=24) { conoutf("texture must be 24bpp: %s", texname); return false; };
    // loopi(s->w*s->h*3) { uchar *p = (uchar *)s->pixels+i; *p = 255-*p; };  
    glBindTexture(GL_TEXTURE_2D, tnum);
    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, clamp ? GL_CLAMP_TO_EDGE : GL_REPEAT);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, clamp ? GL_CLAMP_TO_EDGE : GL_REPEAT);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); //NEAREST);
    glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); 
    xs = s->w;
    ys = s->h;
    while(xs>glmaxtexsize || ys>glmaxtexsize) { xs /= 2; ys /= 2; };
    void *scaledimg = s->pixels;
    if(xs!=s->w)
    {
        conoutf("warning: quality loss: scaling %s", texname);     // for voodoo cards under linux
        scaledimg = alloc(xs*ys*3);
        gluScaleImage(GL_RGB, s->w, s->h, GL_UNSIGNED_BYTE, s->pixels, xs, ys, GL_UNSIGNED_BYTE, scaledimg);
    };
    if(gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB, xs, ys, GL_RGB, GL_UNSIGNED_BYTE, scaledimg)) fatal("could not build mipmaps");
    if(xs!=s->w) free(scaledimg);
    SDL_FreeSurface(s);
    return true;
};
Ejemplo n.º 2
0
void sendmap(char *mapname)
{
    if(*mapname) save_world(mapname);
    changemap(mapname);
    mapname = getclientmap();
    int mapsize;
    uchar *mapdata = readmap(mapname, &mapsize); 
    if(!mapdata) return;
    ENetPacket *packet = enet_packet_create(NULL, MAXTRANS + mapsize, ENET_PACKET_FLAG_RELIABLE);
    uchar *start = packet->data;
    uchar *p = start+2;
    putint(p, SV_SENDMAP);
    sendstring(mapname, p);
    putint(p, mapsize);
    if(65535 - (p - start) < mapsize)
    {
        conoutf("map %s is too large to send", mapname);
        free(mapdata);
        enet_packet_destroy(packet);
        return;
    };
    memcpy(p, mapdata, mapsize);
    p += mapsize;
    free(mapdata); 
    *(ushort *)start = ENET_HOST_TO_NET_16(p-start);
    enet_packet_resize(packet, p-start);
    sendpackettoserv(packet);
    conoutf("sending map %s to server...", mapname);
    sprintf_sd(msg)("[map %s uploaded to server, \"getmap\" to receive it]", mapname);
    toserver(msg);
}
Ejemplo n.º 3
0
void audiomanager::musicpreload(int id)
{
    if(nosound) return;
    stopsound();
    if(musicvol && (id>=M_FLAGGRAB && id<=M_LASTMINUTE2))
    {
        char *name = musics[id];
        conoutf("preloading music #%d : %s", id, name);
        if(gamemusic->open(name))
        {
            defformatstring(whendone)("musicvol %d", musicvol);
            musicdonecmd = newstring(whendone);
            //conoutf("when done: %s", musicdonecmd);
            const int preloadfadetime = 3;
            gamemusic->fadein(lastmillis, preloadfadetime);
            gamemusic->fadeout(lastmillis+2*preloadfadetime, preloadfadetime);
            if(!gamemusic->playback(false))
            {
                conoutf("could not play music: %s", name);
                return;
            }
            setmusicvol(1); // not 0 !
        }
        else conoutf("could not open music: %s", name);
    }
    else setmusicvol(musicvol); // call "musicpreload -1" to ensure musicdonecmd runs - but it should w/o that
}
Ejemplo n.º 4
0
void arenarespawn()
{
    if(arenarespawnwait)
    {
        if(arenarespawnwait<lastmillis)
        {
            arenarespawnwait = 0;
            conoutf("new round starting... fight!");
            respawnself();
        };
    }
    else if(arenadetectwait==0 || arenadetectwait<lastmillis)
    {
        arenadetectwait = 0;
        int alive = 0, dead = 0;
        char *lastteam = NULL;
        bool oneteam = true;
        loopv(players) if(players[i]) arenacount(players[i], alive, dead, lastteam, oneteam);
        arenacount(player1, alive, dead, lastteam, oneteam);
        if(dead>0 && (alive<=1 || (m_teammode && oneteam)))
        {
            conoutf("arena round is over! next round in 5 seconds...");
            if(alive) conoutf("team %s is last man standing", lastteam);
            else conoutf("everyone died!");
            arenarespawnwait = lastmillis+5000;
            arenadetectwait  = lastmillis+10000;
            player1->roll = 0;
        };
    };
Ejemplo n.º 5
0
void audiomanager::music(char *name, int millis, char *cmd)
{
    if(nosound) return;
    stopsound();
    if(musicvol && *name)
    {
        if(cmd[0]) musicdonecmd = newstring(cmd);

        if(gamemusic->open(name))
        {
            // fade
            if(millis > 0)
            {
                const int fadetime = 1000;
                gamemusic->fadein(lastmillis, fadetime);
                gamemusic->fadeout(lastmillis+millis, fadetime);
            }

            // play
            bool loop = cmd && cmd[0];
            if(!gamemusic->playback(loop))
            {
                conoutf("could not play music: %s", name);
                return;
            }
            setmusicvol(musicvol);
        }
        else conoutf("could not open music: %s", name);
    }
}
Ejemplo n.º 6
0
    void init(fpsent *d, int at, int ocn, int sk, int bn, int pm, const char *name, const char *team)
    {
        loadwaypoints();

        fpsent *o = newclient(ocn);

        d->aitype = at;

        bool resetthisguy = false;
        if(!d->name[0])
        {
            if(aidebug) conoutf("%s assigned to %s at skill %d", colorname(d, name), o ? colorname(o) : "?", sk);
            else conoutf("connected: %s", colorname(d, name));
            resetthisguy = true;
        }
        else
        {
            if(d->ownernum != ocn)
            {
                if(aidebug) conoutf("%s reassigned to %s", colorname(d, name), o ? colorname(o) : "?");
                resetthisguy = true;
            }
            if(d->skill != sk && aidebug) conoutf("%s changed skill to %d", colorname(d, name), sk);
        }

        copystring(d->name, name, MAXNAMELEN+1);
        copystring(d->team, team, MAXTEAMLEN+1);
        d->ownernum = ocn;
        d->skill = sk;
        d->playermodel = chooserandomplayermodel(pm);

        if(resetthisguy) removeweapons(d);
        if(player1->clientnum == d->ownernum) create(d);
        else if(d->ai) destroy(d);
    }
Ejemplo n.º 7
0
    void run(const char *map) {
        if (started) {
            conoutf("Stopping old server instance ..");
            stop();
        }
        conoutf("Starting server, please wait ..");
#ifndef WIN32
        if (!fork()) {
            const char *a0 = "bin_unix/server_" BINARY_OS_STR "_"
                BINARY_ARCH_STR;

            defformatstring(a1, "-g%s", logger::names[logger::current_level]);
            defformatstring(a2, "-l%s", server_log_file);
            defformatstring(a3, "-mmap/%s.tar.gz", map);

            execl(a0, a0, a1, a2, a3, "-shutdown-if-idle",
                "-shutdown-if-empty", (char*)NULL);
            exit(0);
        }
#else
#ifdef WIN64
        const char *exe = "bin_win64\\server_" BINARY_OS_STR "_"
            BINARY_ARCH_STR ".exe";
#else
        const char *exe = "bin_win32\\server_" BINARY_OS_STR "_"
            BINARY_ARCH_STR ".exe";
#endif
        char buf[4096];
        char *cptr = buf;

        defformatstring(a1, "-g%s", logger::names[logger::current_level]);
        defformatstring(a2, "-l%s", server_log_file);
        defformatstring(a3, "-mmap/%s.tar.gz", map);
        const char a4[] = "-shutdown-if-idle";
        const char a5[] = "-shutdown-if-empty";

        size_t len = strlen(a1);
        memcpy(cptr, a1, len); cptr += len; *(cptr++) = ' ';
        len = strlen(a2);
        memcpy(cptr, a2, len); cptr += len; *(cptr++) = ' ';
        len = strlen(a3);
        memcpy(cptr, a3, len); cptr += len; *(cptr++) = ' ';
        len = sizeof(a4) - 1;
        memcpy(cptr, a4, len); cptr += len; *(cptr++) = ' ';
        len = sizeof(a5) - 1;
        memcpy(cptr, a5, len); cptr += len; *cptr = '\0';

        STARTUPINFO si;
        PROCESS_INFORMATION pi;
        ZeroMemory(&si, sizeof(si));
        si.cb = sizeof(si);
        ZeroMemory(&si, sizeof(pi));

        CreateProcess(exe, buf, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
        CloseHandle(pi.hProcess);
        CloseHandle(pi.hThread);
#endif

        started = true;
    }
Ejemplo n.º 8
0
void savegame(char *name)
{
    if(!m_classicsp) { conoutf("can only save classic sp games"); return; };
    sprintf_sd(fn)("savegames/%s.csgz", name);
    savestate(fn);
    stop();
    conoutf("wrote %s", fn);
};
	static use *checkuse(int type)
	{
		if(!loadinguse)
			conoutf(CON_ERROR, "\fs\f3ERROR:\fr use not defined or being loaded");
		else if(loadinguse->type < type)
			conoutf(CON_ERROR, "\fs\f3ERROR:\fr trying to set an unavailable use property");
		else
			return loadinguse;
		return NULL;
	}
Ejemplo n.º 10
0
void paste()
{
    EDITMP;
    if(!copybuf) { conoutf("nothing to paste"); return; };
    sel.xs = copybuf->xs;
    sel.ys = copybuf->ys;
    correctsel();
    if(!selset || sel.xs!=copybuf->xs || sel.ys!=copybuf->ys) { conoutf("incorrect selection"); return; };
    makeundo();
    copybuf->x = sel.x;
    copybuf->y = sel.y;
    blockpaste(*copybuf);
};
Ejemplo n.º 11
0
void record(char *name)
{
    if(m_sp) { conoutf("cannot record singleplayer games"); return; };
    int cn = getclientnum();
    if(cn<0) return;
    sprintf_sd(fn)("demos/%s.cdgz", name);
    savestate(fn);
    gzputi(cn);
    conoutf("started recording demo to %s", fn);
    demorecording = true;
    starttime = lastmillis;
	ddamage = bdamage = 0;
};
Ejemplo n.º 12
0
static void ignorelist()
{
    if (ips.isempty())
    {
        conoutf("ip ignore list is empty");
        return;
    }

    conoutf("ignoring %u ip%s", (uint)ips.getsize(), plural(ips.getsize()));

    int counter = 0;
    ips.loopips(showignoredip, &counter);
}
Ejemplo n.º 13
0
	void Client::initConnect(int cn, int protocol)
	{
	    conoutf("Client::initConnect");
		if(protocol!=CubeJ::PROTOCOL_VERSION)
		{
			conoutf(CON_ERROR, "you are using a different game protocol (you: %d, server: %d)", CubeJ::PROTOCOL_VERSION, protocol);
			disconnect();
			return;
		}

		self.clientnum = cn;
        CubeJ::MsgDataType<CubeJ::MSG_REQ_CONNECT> data(self.name);
        SendMessage(data);
    }
Ejemplo n.º 14
0
void trydisconnect()
{
    if(connpeer)
    {
        conoutf("aborting connection attempt");
        abortconnect();
    }
    else if(curpeer)
    {
        conoutf("attempting to disconnect...");
        disconnect(!discmillis);
    }
    else conoutf("not connected");
}
Ejemplo n.º 15
0
void trydisconnect(bool local)
{
    if(connpeer)
    {
        conoutf("aborting connection attempt");
        abortconnect();
    }
    else if(curpeer)
    {
        conoutf("attempting to disconnect...");
        disconnect(!discmillis);
    }
    else if(local && haslocalclients()) localdisconnect();
    else conoutf("not connected");
}
Ejemplo n.º 16
0
 void takefromplayer(char *name, char *ok, char *notok)
 {
     rpgobj *o = playerobj->take(name);
     if(o)
     {
         stack[0]->add(o, false);
         conoutf("\f2you hand over a %s", o->name);
         if(currentquest)
         {
             conoutf("\f2you finish a quest for %s", currentquest->npc); 
             currentquest->completed = true;           
         }
     }
     execute(o ? ok : notok);
 }
Ejemplo n.º 17
0
void connectserv(const char *servername, int serverport, const char *serverpassword)
{
    if(connpeer)
    {
        conoutf("aborting connection attempt");
        abortconnect();
    }

    if(serverport <= 0) serverport = server::serverport();

    ENetAddress address;
    address.port = serverport;

    if(servername)
    {
        if(strcmp(servername, connectname)) setsvar("connectname", servername);
        if(serverport != connectport) setvar("connectport", serverport);
        conoutf("attempting to connect to %s:%d", servername, serverport);
        if(!resolverwait(servername, &address))
        {
            conoutf("\f3could not resolve server %s", servername);
            return;
        }
    }
    else
    {
        setsvar("connectname", "");
        setvar("connectport", 0);
        conoutf("attempting to connect over LAN");
        address.host = ENET_HOST_BROADCAST;
    }

    if(!clienthost)
    {
        clienthost = enet_host_create(NULL, 2, server::numchannels(), rate*1024, rate*1024);
        if(!clienthost)
        {
            conoutf("\f3could not connect to server");
            return;
        }
        clienthost->duplicatePeers = 0;
    }

    connpeer = enet_host_connect(clienthost, &address, server::numchannels(), 0);
    enet_host_flush(clienthost);
    connmillis = totalmillis;
    connattempts = 0;
}
Ejemplo n.º 18
0
void stopreset()
{
    conoutf("demo stopped (%d msec elapsed)", lastmillis-starttime);
    stop();
    loopv(players) zapdynent(players[i]);
    disconnect(0, 0);
};
Ejemplo n.º 19
0
void savestate(char *fn) {
	stop();
	f = gzopen(fn, "wb9");
	if (!f) {
		conoutf("could not write %s", fn);
		return;
	};
	gzwrite(f, (void *) "CUBESAVE", 8);
	gzputc(f, islittleendian);
	gzputi(SAVEGAMEVERSION);
	gzputi(sizeof(Sprite));
	char buf[_MAXDEFSTR];
	sprintf(buf, "%s", getclientmap().c_str());
	gzwrite(f, buf, _MAXDEFSTR);
	gzputi(gamemode);
	gzputi(entityList.size());
	for(Entity &en : entityList) {
		gzputc(f, en.spawned);
	}
	gzwrite(f, player1, sizeof(Sprite));
	std::vector<Sprite *> &monsters = getmonsters();
	gzputi(monsters.size());
	for(Sprite *m : monsters) {
		gzwrite(f, m, sizeof(Sprite));
	}
	gzputi(players.size());
	for(Sprite *p : players) {
		gzput(p == NULL);
		gzwrite(f, p, sizeof(Sprite));
	};
}
Ejemplo n.º 20
0
 void stopfollowing()
 {
     if(following<0) return;
     following = -1;
     followdir = 0;
     conoutf("follow off");
 }
Ejemplo n.º 21
0
    bool execcfg(const char *cfgfile, bool ignore_ret)
    {
        string s;
        copystring(s, cfgfile);
        char *buf = loadfile(path(s), NULL);
        if(!buf) return false;
        auto err = lapi::state.do_string(buf, lua::ERROR_TRACEBACK);
        if (types::get<0>(err))
            logger::log(logger::ERROR, "%s\n", types::get<1>(err));

        bool ret = true;
        if (!ignore_ret)
        {
            ret = lapi::state["OF_CFG_VERSION_PASSED"].to<bool>();
            if (!ret)
            {
                conoutf(
                    "Your OctaForge config file was too old to run with "
                    "your current client. Initializing a default set."
                );
            }
            lapi::state["OF_CFG_VERSION_PASSED"] = lua::nil;
        }

        delete[] buf;
        return ret;
    }
Ejemplo n.º 22
0
void disconnect(bool async, bool cleanup)
{
    if(curpeer)
    {
        if(!discmillis)
        {
            enet_peer_disconnect(curpeer, DISC_NONE);
            enet_host_flush(clienthost);
            discmillis = totalmillis;
        }
        if(curpeer->state!=ENET_PEER_STATE_DISCONNECTED)
        {
            if(async) return;
            enet_peer_reset(curpeer);
        }
        curpeer = NULL;
        discmillis = 0;
        conoutf("disconnected");
        game::gamedisconnect(cleanup);
        setvar("mainmenu", 1);
    }
    if(!connpeer && clienthost)
    {
        enet_host_destroy(clienthost);
        clienthost = NULL;
    }
}
Ejemplo n.º 23
0
	void Client::connectRemoteInterface(int n) {
		conoutf("[DEBUG] Client::connectRemoteInterface, clientnum: %d", n);
		remoteclientnum = n;
		clients.add(new ClientInfo (n, CLIENT_TYPE_REMOTE, NULL));
        CubeJ::MsgDataType<CubeJ::MSG_ACK_REMOTE> data(n);
        SendMessage(data);
	}
Ejemplo n.º 24
0
//! Upload the last map once more. This does NOT save the world - it can be called without
//! even having a world loaded (e.g., from the main menu, right after startup). It simply
//! packages the files in the map directory and uploads them. This is useful for making
//! fixes to map scripts that crash the server, but can also be used after manually
//! replacing the .ogz file, etc.
void repeat_upload()
{
    std::string lastUploadedMapAsset = last_uploaded_map_asset;

    // Acquire the asset info, so we know its file locations, asset server, etc.
    renderprogress(0.2, "getting map asset info...");
    REFLECT_PYTHON( AssetManager );
    boost::python::object assetInfo = AssetManager.attr("get_info")( lastUploadedMapAsset );

    // Set the map asset ID to the last one uploaded
    REFLECT_PYTHON( set_curr_map_asset_id );
    set_curr_map_asset_id( lastUploadedMapAsset );
    REFLECT_PYTHON( World );
    World.attr("asset_info") = assetInfo;

//    // Make sure the script compiles ok TODO: All scripts, not just the main one
//    renderprogress(0.5, "compiling scripts...");
//    REFLECT_PYTHON( get_map_script_filename );
//    std::string filename = boost::python::extract<std::string>( get_map_script_filename() );
//    if (!checkCompile(filename)) XXX - need engine for this!
//        return;

    // Do the upload
    renderprogress(0.7, "compiling scripts...");
    REFLECT_PYTHON( upload_map );
    upload_map();

    conoutf("Upload complete.");
}
Ejemplo n.º 25
0
void stopn() {
	if (demoplayback)
		stopreset();
	else
		stop();
	conoutf("demo stopped");
}
Ejemplo n.º 26
0
static void showglslinfo(GLenum type, GLuint obj, const char *name, const char **parts = NULL, int numparts = 0)
{
    GLint length = 0;
    if(type) glGetShaderiv_(obj, GL_INFO_LOG_LENGTH, &length);
    else glGetProgramiv_(obj, GL_INFO_LOG_LENGTH, &length);
    if(length > 1)
    {
        conoutf(CON_ERROR, "GLSL ERROR (%s:%s)", type == GL_VERTEX_SHADER ? "VS" : (type == GL_FRAGMENT_SHADER ? "FS" : "PROG"), name);
        FILE *l = getlogfile();
        if(l)
        {
            GLchar *log = new GLchar[length];
            if(type) glGetShaderInfoLog_(obj, length, &length, log);
            else glGetProgramInfoLog_(obj, length, &length, log);
            fprintf(l, "%s\n", log);
            bool partlines = log[0] != '0';
            int line = 0;
            loopi(numparts)
            {
                const char *part = parts[i];
                int startline = line;
                while(*part)
                {
                    const char *next = strchr(part, '\n');
                    if(++line > 1000) goto done;
                    if(partlines) fprintf(l, "%d(%d): ", i, line - startline); else fprintf(l, "%d: ", line);
                    fwrite(part, 1, next ? next - part + 1 : strlen(part), l);
                    if(!next) { fputc('\n', l); break; }
                    part = next + 1;
                }
            }
        done:
            delete[] log;
        }
    }
Ejemplo n.º 27
0
void connectserv(const char *servername, int serverport, const char *serverpassword)
{   
    if(connpeer)
    {
        conoutf("aborting connection attempt");
        abortconnect();
    }

    if(serverport <= 0) serverport = server::serverport();

    ENetAddress address;
    address.port = serverport;

    if(servername)
    {
        if(strcmp(servername, GETSV(connectname))) SETVF(connectname, servername);
        if(serverport != GETIV(connectport)) SETVF(connectport, serverport);
        addserver(servername, serverport, serverpassword && serverpassword[0] ? serverpassword : NULL); // INTENSITY: Remove?
        conoutf("attempting to connect to %s:%d", servername, serverport);
        if(!resolverwait(servername, &address))
        {
            conoutf("\f3could not resolve server %s", servername);
            return;
        }
    }
    else
    {
        SETVF(connectname, "");
        SETVF(connectport, 0);
        conoutf("attempting to connect over LAN");
        address.host = ENET_HOST_BROADCAST;
    }

    if(!clienthost) 
        clienthost = enet_host_create(NULL, 2, server::numchannels(), GETIV(rate), GETIV(rate));

    if(clienthost)
    {
        connpeer = enet_host_connect(clienthost, &address, server::numchannels(), 0); 
        enet_host_flush(clienthost);
        connmillis = totalmillis;
        connattempts = 0;

        game::connectattempt(servername ? servername : "", serverpassword ? serverpassword : "", address);
    }
    else conoutf("\f3could not connect to server");
}
Ejemplo n.º 28
0
 void finalize()
 {
     center = vec(bbmin).add(bbmax).mul(0.5f);
     radius = bbmin.dist(bbmax)/2;
     cullmin = ivec::floor(bbmin);
     cullmax = ivec::ceil(bbmax);
     if(dbgpseed) conoutf(CON_DEBUG, "radius: %f, maxfade: %d", radius, maxfade);
 }
Ejemplo n.º 29
0
 void finalize()
 {
     center = vec(bbmin).add(bbmax).mul(0.5f);
     radius = bbmin.dist(bbmax)/2;
     bborigin = ivec(int(floor(bbmin.x)), int(floor(bbmin.y)), int(floor(bbmin.z)));
     bbsize = ivec(int(ceil(bbmax.x)), int(ceil(bbmax.y)), int(ceil(bbmax.z))).sub(bborigin);
     if(dbgpseed) conoutf(CON_DEBUG, "radius: %f, maxfade: %d", radius, maxfade);
 }
Ejemplo n.º 30
0
void editundo()
{
    EDITMP;
    if(undos.empty()) { conoutf("nothing more to undo"); return; };
    block *p = undos.pop();
    blockpaste(*p);
    free(p);
};