Exemplo n.º 1
0
bool GameRootLinux::isLocked()
{
    Ogre::UTFString homeDir = this->getHomeDirectory();

    // check if the folder exists otherwise create it
    if (opendir(homeDir.asUTF8_c_str()) == nullptr)
    {
        if (mkdir(homeDir.asUTF8_c_str(), S_IRWXU|S_IRGRP|S_IXGRP) != 0)
        {
            OGRE_EXCEPT(Ogre::Exception::ERR_INVALID_STATE, "Can not create folder in home directory", "GameRootLinux::isLocked");
        }
    }

    homeDir = homeDir+Ogre::UTFString("/pid");

    std::fstream runfile;
    char* buf;
    int len, pid;
    runfile.open(homeDir.asUTF8_c_str(), std::fstream::in | std::fstream::out | std::fstream::app);

    // No file, game not running
    if (!runfile.is_open())
        return false;

    runfile.seekg (0, std::ios::end);
    len = runfile.tellg();
    runfile.seekg (0, std::ios::beg);

    if (len > 20)
    {
        // should only store a number         
        runfile.close();
        return true;
    }
    buf = OGRE_NEW char[len];
    runfile.read(buf,len);
    runfile.close();

    pid = atoi(buf);

    OGRE_DELETE buf;
    buf = 0;

    if (pid < 1)
        return false;

    Ogre::String proc = "/proc/"+Ogre::StringConverter::toString(pid)+"/status";
    runfile.open(proc.c_str(), std::fstream::in);

    // No file, game not running
    if (!runfile.is_open())
        return false;

    runfile.close();
    return true;
}
Exemplo n.º 2
0
void GameRootLinux::setLocked(const bool& locked)
{
    Ogre::UTFString homeDir = this->getHomeDirectory() + Ogre::UTFString("/pid");
    std::fstream runfile;
    std::string buf;

    remove(homeDir.asUTF8_c_str());
    if (locked)
    {
        buf = Ogre::String(Ogre::StringConverter::toString(getpid()));
        runfile.open(homeDir.asUTF8_c_str(), std::fstream::in | std::fstream::out | std::fstream::app);
        runfile.write(buf.c_str(),buf.size());
        runfile.close();
    }
}
Exemplo n.º 3
0
void SendPrivateChat(int target_uid, Ogre::UTFString chatline, Ogre::UTFString target_username)
{
#ifdef USE_SOCKETW
	char buffer[MAX_MESSAGE_LENGTH] = {0};
	
	const char *chat_msg = (const char *)chatline.asUTF8_c_str();

	// format: int of UID, then chat message
	memcpy(buffer, &target_uid, sizeof(int));
	strncpy(buffer + sizeof(int), chat_msg, MAX_MESSAGE_LENGTH - sizeof(int));

	size_t len = sizeof(int) + chatline.size() * sizeof(wchar_t);
	buffer[len] = 0;

	RoR::Networking::AddPacket(m_stream_id, MSG2_UTF_PRIVCHAT, (unsigned int)len, buffer);

	if (target_username.empty())
	{
		user_info_t user;
		if (RoR::Networking::GetUserInfo(target_uid, user))
		{
			target_username = GetColouredName(user.username, user.colournum);
		}
	}

	// add local visual
	Ogre::UTFString local_username = GetColouredName(RoR::Networking::GetUsername(), RoR::Networking::GetUserColor());
	Ogre::UTFString nmsg = local_username + RoR::Color::WhisperColour + _L(" [whispered to ") + RoR::Color::NormalColour + target_username + RoR::Color::WhisperColour + "]" + RoR::Color::NormalColour + ": " + chatline;
#ifdef USE_MYGUI
	RoR::Application::GetGuiManager()->pushMessageChatBox(nmsg);
#endif // USE_MYGUI
#endif // USE_SOCKETW
}
Exemplo n.º 4
0
void SendChat(Ogre::UTFString chatline)
{
#ifdef USE_SOCKETW
	const char *utf8_line = chatline.asUTF8_c_str();
	RoR::Networking::AddPacket(m_stream_id, MSG2_UTF_CHAT, (unsigned int)strlen(utf8_line), (char *)utf8_line);
#endif // USE_SOCKETW
}
Exemplo n.º 5
0
void ChatSystem::sendPrivateChat(int target_uid, Ogre::UTFString chatline, Ogre::UTFString username)
{
#ifdef USE_SOCKETW
	char buffer[MAX_MESSAGE_LENGTH] = "";
	
	const char *chat_msg = (const char *)chatline.asUTF8_c_str();

	// format: int of UID, then chat message
	memcpy(buffer, &target_uid, sizeof(int));
	strncpy(buffer + sizeof(int), chat_msg, MAX_MESSAGE_LENGTH - sizeof(int));

	size_t len = sizeof(int) + chatline.size() * sizeof(wchar_t);
	buffer[len] = 0;

	this->addPacket(MSG2_UTF_PRIVCHAT, (unsigned int)len, buffer);

	if(username.empty())
	{
		client_t *c = net->getClientInfo(target_uid);
		if(c) username = getColouredName(*c);
	}

	// add local visual
#ifdef USE_MYGUI
	UTFString nmsg = net->getNickname(true) + normalColour + whisperColour + _L(" [whispered to ") + normalColour + username + whisperColour + "]" + normalColour + ": " + chatline;
	Console::getInstance().putMessage(Console::CONSOLE_MSGTYPE_NETWORK, Console::CONSOLE_LOCAL_CHAT, nmsg, "script_key.png");
#endif // USE_MYGUI
#endif // USE_SOCKETW
}
Exemplo n.º 6
0
int showMsgBox(Ogre::UTFString title, Ogre::UTFString err, int type)
{
    // we might call the showMsgBox without having ogre created yet!
    //LOG("message box: " + title + ": " + err);
#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
    int mtype = MB_ICONERROR;
    if(type == 1) mtype = MB_ICONINFORMATION;
    MessageBoxW( NULL, err.asWStr_c_str(), title.asWStr_c_str(), MB_OK | mtype | MB_TOPMOST);
#elif OGRE_PLATFORM == OGRE_PLATFORM_LINUX
    printf("\n\n%s: %s\n\n", title.asUTF8_c_str(), err.asUTF8_c_str());
#elif OGRE_PLATFORM == OGRE_PLATFORM_APPLE
    printf("\n\n%s: %s\n\n", title.asUTF8_c_str(), err.asUTF8_c_str());
    //CFOptionFlags flgs;
    //CFUserNotificationDisplayAlert(0, kCFUserNotificationStopAlertLevel, NULL, NULL, NULL, T("A network error occured"), T("Bad server port."), NULL, NULL, NULL, &flgs);
#endif
    return 0;
}
Exemplo n.º 7
0
int showOgreWebError(Ogre::UTFString title, Ogre::UTFString err, Ogre::UTFString url)
{
#ifndef NOOGRE
    // this only works in non-embedded mode
    // make no sense in embedded mode anyways ...

    storederror = true;
    stored_title = title;
    stored_err = err;
    stored_url = url;

    RigsOfRods *ror = RigsOfRods::getSingletonPtr();
    if(ror) ror->tryShutdown();

#if OGRE_PLATFORM == OGRE_PLATFORM_LINUX
    printf("\n\n%s: %s / url: %s\n\n", title.asUTF8_c_str(), err.asUTF8_c_str(), url.asUTF8_c_str());
#endif
    return 0;
#else
    return showWebError(Ogre::UTFString("Rigs of Rods: ") + title, err, url);
#endif //NOOGRE
}
Exemplo n.º 8
0
// Helper function
void Character::ReportError(const char* detail)
{
#ifdef USE_SOCKETW
    Ogre::UTFString username;
    RoRnet::UserInfo info;
    if (!RoR::Networking::GetUserInfo(m_source_id, info))
        username = "******";
    else
        username = info.username;

    char msg_buf[300];
    snprintf(msg_buf, 300,
        "[RoR|Networking] ERROR on m_is_remote character (User: '******', SourceID: %d, StreamID: %d): ",
        username.asUTF8_c_str(), m_source_id, m_stream_id);

    LOGSTREAM << msg_buf << detail;
#endif
}
Exemplo n.º 9
0
int showWebError(Ogre::UTFString title, Ogre::UTFString err, Ogre::UTFString url)
{
    // NO logmanager use, because it could be that its not initialized yet!
    //LOG("web message box: " + title + ": " + err + " / url: " + url);
#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
    Ogre::UTFString additional = _L("\n\nYou can eventually get help here:\n\n") + url + _L("\n\nDo you want to open that address in your default browser now?");
    err = err + additional;
    int Response = MessageBoxW( NULL, err.asWStr_c_str(), title.asWStr_c_str(), MB_YESNO | MB_ICONERROR | MB_TOPMOST | MB_SYSTEMMODAL | MB_SETFOREGROUND );
    // 6 (IDYES) = yes, 7 (IDNO) = no
    if(Response == IDYES)
    {
        // Microsoft conversion hell follows :|
        wchar_t *command = L"open";
        ShellExecuteW(NULL, command, url.asWStr_c_str(), NULL, NULL, SW_SHOWNORMAL);
    }
#elif OGRE_PLATFORM == OGRE_PLATFORM_LINUX
    printf("\n\n%s: %s / url: %s\n\n", title.asUTF8_c_str(), err.asUTF8_c_str(), url.asUTF8_c_str());
#elif OGRE_PLATFORM == OGRE_PLATFORM_APPLE
    printf("\n\n%s: %s / url: %s\n\n", title.asUTF8_c_str(), err.asUTF8_c_str(), url.asUTF8_c_str());
    //CFOptionFlags flgs;
    //CFUserNotificationDisplayAlert(0, kCFUserNotificationStopAlertLevel, NULL, NULL, NULL, "An exception has occured!", err.c_str(), NULL, NULL, NULL, &flgs);
#endif
    return 0;
}
Exemplo n.º 10
0
void ChatSystem::sendChat(Ogre::UTFString chatline)
{
	const char *utf8_line = chatline.asUTF8_c_str();
	this->addPacket(MSG2_UTF_CHAT, (unsigned int)strlen(utf8_line), (char *)utf8_line);
}