Example #1
0
}

bool ResourceManager::removeFromSearchPath(const std::string &path) const
{
    logger->log("Removing from PhysicsFS: %s", path.c_str());
    if (!PhysFs::removeFromSearchPath(path.c_str()))
    {
        logger->log("Error: %s: removeFromSearchPath failed: %s",
            path.c_str(),
            PHYSFS_getLastError());
        return false;
    }
    return true;
}

void ResourceManager::searchAndAddArchives(const std::string &restrict path,
                                           const std::string &restrict ext,
                                           const Append append) const
{
    const char *const dirSep = dirSeparator;
    char **list = PhysFs::enumerateFiles(path.c_str());

    for (char **i = list; *i; i++)
    {
        const size_t len = strlen(*i);

        if (len > ext.length() && !ext.compare((*i) + (len - ext.length())))
        {
            const std::string file = path + (*i);
            const std::string realPath = std::string(
                PhysFs::getRealDir(file.c_str()));
            addToSearchPath(std::string(realPath).append(
Example #2
0
    {
        const int comp = tolower(*itA) - tolower(*itB);
        if (comp != 0)
            return comp;
    }

    // Check string lengths
    if (itA == endA && itB == endB)
        return 0;
    else if (itA == endA)
        return -1;
    else
        return 1;
}

const std::string findSameSubstring(const std::string &restrict str1,
                                    const std::string &restrict str2)
{
    const int minLength = str1.length() > str2.length()
        ? CAST_S32(str2.length()) : CAST_S32(str1.length());
    for (int f = 0; f < minLength; f ++)
    {
        if (str1.at(f) != str2.at(f))
            return str1.substr(0, f);
    }
    return str1.substr(0, minLength);
}

const std::string findSameSubstringI(const std::string &restrict s1,
                                     const std::string &restrict s2)
{
    std::string str1 = s1;
Example #3
0
    outMsg.writeInt16(0, "unused");
}

void GuildHandler::leave(const int guildId) const
{
    if (localPlayer == nullptr)
        return;

    createOutPacket(CMSG_GUILD_LEAVE);
    outMsg.writeInt32(guildId, "guild id");
    outMsg.writeBeingId(localPlayer->getId(), "account id");
    outMsg.writeInt32(PlayerInfo::getCharId(), "char id");
    outMsg.writeString("", 40, "message");
}

void GuildHandler::kick(const GuildMember *restrict const member,
                        const std::string &restrict reason) const
{
    if ((member == nullptr) || (member->getGuild() == nullptr))
        return;

    createOutPacket(CMSG_GUILD_EXPULSION);
    outMsg.writeInt32(member->getGuild()->getId(), "guild id");
    outMsg.writeBeingId(member->getID(), "account id");
    outMsg.writeInt32(member->getCharId(), "char id");
    outMsg.writeString(reason, 40, "message");
}

void GuildHandler::chat(const std::string &text) const
{
    if (localPlayer == nullptr)
        return;
Example #4
0
File: music.c Project: mina86/music
/****************************** Main ******************************/
int main(int argc, char **argv) {
	struct config cfg = {
		PTHREAD_MUTEX_INITIALIZER,
		0, LOG_NOTICE, 0,
		0
	};
	struct music_module core = {
		-1,
		0, 0, 0,
		config_line,
		{ 0 }, 0,
		0, 0,
		(char*)"core",
		0
	}, *m;
	char *ch;
	int i, returnValue = 0, pipe_fds[2];

	core.core = &core;
	core.data = &cfg;


	/***** Get program name *****/
	for (core.name = ch = *argv; *ch; ++ch) {
		if ((*ch=='/' || *ch=='\\') && ch[1] && ch[1]!='/' && ch[1]!='\\') {
			core.name = ch + 1;
		}
	}


	/***** Help *****/
	if (argc>=2 && (!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help"))) {
		fputs("usage: music [ config-file ... ]\n", stdout);
		return 0;
	}


	/***** Read config *****/
	if (argc<2) {
		argv[1] = (char*)"-";
		argc = 2;
	}

	for (i = 1; i < argc; ++i) {
		FILE *fp = strcmp(argv[i], "-") ? fopen(argv[i], "r") : stdin;
		char buf[1026];

		if (!fp) {
			music_log_errno(&core, LOG_FATAL, "open: %s", argv[i]);
			return 1;
		}

		m = &core;
		if (ch) *ch = 0;
		while (fgets(buf, sizeof buf, fp)) {
			int result = !parse_line(buf, &m);
			if (result) return result;
		}

		if (fp!=stdin) {
			fclose(fp);
		}
	}

	struct music_module *dispatcher_init();
	m = dispatcher_init();
	if (!m) {
		music_log(&core, LOG_FATAL, "Error initialising song dispatcher");
		return 1;
	}
	m->name = music_strdup_realloc(0, "dispatcher");
	m->next = core.next;
	m->core = &core;
	core.next = m;

	if (!sort_modules(&core)) {
		return 1;
	}



	/***** Open log file *****/
	if (cfg.logfile && *cfg.logfile) {
		i = open(cfg.logfile, O_WRONLY | O_APPEND | O_CREAT, 0600);
		if (i==-1) {
			music_log_errno(&core, LOG_FATAL, "open: %s", cfg.logfile);
			return 1;
		}
		fflush(stderr);
		dup2(i, 2); /* stderr is not logfile */
		close(i);
	}

	music_log(&core, LOG_NOTICE, "starting");
	cfg.logboth = 1;


	/***** Daemonize *****/
	switch (fork()) {
	case -1:
		music_log_errno(&core, LOG_FATAL, "fork");
		return 1;
	case  0: break;
	default: return 0;
	}

	setsid();

	switch (fork()) {
	case -1:
		music_log_errno(&core, LOG_FATAL, "fork");
		return 1;
	case  0: break;
	default: return 0;
	}

	chdir("/");
	cfg.logboth = 0;
	i = sysconf(_SC_OPEN_MAX);
	while (--i > 2) {
		close(i);
	}
	close(0);
	open("/dev/null", O_RDWR); /* stdin  is /dev/null */
	fflush(stdout);
	dup2(0, 1);                /* stdout is /dev/null */


	/***** Create sleep pipe *****/
	if (pipe(pipe_fds)) {
		music_log_errno(&core, LOG_FATAL, "pipe");
		return 1;
	}
	sleep_pipe_fd = pipe_fds[0];


	/***** Register signal handler *****/
	signal(SIGHUP,  got_sig);
	signal(SIGINT,  got_sig);
	signal(SIGILL,  got_sig);
	signal(SIGQUIT, got_sig);
	signal(SIGSEGV, got_sig);
	signal(SIGTERM, got_sig);
	signal(SIGALRM, ignore_sig);


	/***** Start cache *****/
	m = &core;
	while (m->next && m->next->type==MUSIC_CACHE) {
		struct music_module *prev = m;
		m = m->next;

		if (sig) {
			goto finishSig;
		}

		music_log(m, LOG_NOTICE, "starting");
		if (!m->start || m->start(m)) {
			music_log(m, LOG_DEBUG, "this will be our cache");
			break;
		}

		music_log(m, LOG_FATAL + 2, "error starting module");
		prev->next = m->next;
		if (m->free) m->free(m);
		free(m);
		m = prev;
	}

	/* Check cache */
	if (m==&core && cfg.requireCache) {
		music_log(m, LOG_FATAL, "no cache started");
		returnValue = 1;
		goto finishNoStop;
	}

	/* Free rest of the caches */
	while (m->next && m->next->type==MUSIC_CACHE) {
		struct music_module *next = m->next;
		m->next = next->next;
		if (next->free) next->free(next);
		if (next->name) free(next->name);
		free(next);
	}


	/***** Start other modules *****/
	while (m->next) {
		struct music_module *prev = m;
		m = m->next;

		if (sig) {
			goto finishSig;
		}

		music_log(m, LOG_NOTICE, "starting");
		if (m->start && !m->start(m)) {
			music_log(m, LOG_FATAL, "error starting module");
			prev->next = 0;
			returnValue = 1;
			goto finishNoSig;
		}
	}


	/***** Run *****/
	while (music_running) {
		pause();
	}


	/***** Check signal *****/
	if (sig) {
	finishSig:
		music_log(&core, LOG_NOTICE + 2, "got signal %d; exiting", sig);
	}

 finishNoSig:
	/* Stop everything */
	write(pipe_fds[1], "B", 1);
	for (m = core.next; m; m = m->next) {
		music_log(m, LOG_NOTICE + 2, "stopping");
		if (m->stop) m->stop(m);
	}

 finishNoStop:
	/* OS will free all resources we were using so no need to do it
	   ourselfves */
	music_log(&core, LOG_NOTICE, "terminated");
	return returnValue;
}
SDL2SoftwareGraphics::SDL2SoftwareGraphics() :
    Graphics(),
    mRendererFlags(SDL_RENDERER_SOFTWARE),
    mSurface(nullptr),
    mOldPixel(0),
    mOldAlpha(0)
{
    mOpenGL = RENDER_SOFTWARE;
    mName = "Software";
}

SDL2SoftwareGraphics::~SDL2SoftwareGraphics()
{
}

void SDL2SoftwareGraphics::drawRescaledImage(const Image *restrict const image,
                                             int dstX, int dstY,
                                             const int desiredWidth,
                                             const int desiredHeight) restrict2
{
    FUNC_BLOCK("Graphics::drawRescaledImage", 1)
    // Check that preconditions for blitting are met.
    if (!mSurface || !image || !image->mSDLSurface)
        return;

    Image *const tmpImage = image->SDLgetScaledImage(
        desiredWidth, desiredHeight);

    if (!tmpImage || !tmpImage->mSDLSurface)
        return;

    const ClipRect &top = mClipStack.top();
Example #6
0
#include "debug.h"

namespace Ea
{

ChatHandler::ChatHandler()
{
    if (!ChatRecv::mSentWhispers.empty())
        ChatRecv::mSentWhispers.pop();
    ChatRecv::mMotdTime = -1;
    ChatRecv::mShowAllLang = serverConfig.getValue("showAllLang", 0);
    ChatRecv::mShowMotd = config.getBoolValue("showmotd");
    ChatRecv::mSkipping = true;
}

void ChatHandler::clear()
{
    ChatRecv::mShowMotd = config.getBoolValue("showmotd");
    ChatRecv::mSkipping = true;
}

void ChatHandler::me(const std::string &restrict text,
                     const std::string &restrict channel) const
{
    // here need string duplication
    std::string action = strprintf("*%s*", text.c_str());
    talk(action, channel);
}

}  // namespace Ea