void TestAuthErr() {
  EscalateHelper *helper = NULL;
  GIOChannel *stdin_writer = NULL;
  GIOChannel *stdout_reader = NULL;
  GThread *helper_thread = NULL;

  EscalateTestSetIds(100, 0, 100, 0);
  EscalateTestMockAuthenticate(auth_err_prompts, PAM_AUTH_ERR);

  CreateHelper(&helper, &stdin_writer, &stdout_reader);
  helper_thread = RunHelperThread(helper);

  WriteMessage(stdin_writer,
               "(1, <(1, 0, 'janedoe', {3: @ms '/dev/pts/9000'})>)");
  AssertMessage(stdout_reader, "(2, <(1, 'Password: '******'testpass', 0)>)");
  AssertMessage(stdout_reader, "(2, <(4, 'Failed!')>)");
  WriteMessage(stdin_writer, "(3, <(@ms nothing, 0)>)");
  AssertMessage(stdout_reader, "(4, <(7,)>)");

  JoinHelperThread(helper_thread);
  EscalateHelperFree(helper);
  g_io_channel_unref(stdin_writer);
  g_io_channel_unref(stdout_reader);
}
Пример #2
0
Sound* SoundManager::loadSound2(const char* filename, bool alternative)
{
	outputln(std::string("Loading sound:    ") + filename << " (shared)");
#if defined(USES_SDL_FOR_SOUND)
	
	Mix_Chunk* sound = Mix_LoadWAV( filename );
	if (sound == NULL) AssertMessage(false, "Could not open WAV sound file");
	return reinterpret_cast<Sound*>(new Sound_Basic(sound));
#elif defined(USES_WINDOWS_OPENGL) || defined(USES_LINUX)
	unsigned int bufferID;
	unsigned int sourceID;
	SoundLoad::loadSound(filename, &bufferID, &sourceID);
	return reinterpret_cast<Sound*>(new Sound_Basic(bufferID, sourceID));
#elif defined(USES_WINDOWS8_DESKTOP) || defined(USES_WINDOWS8_METRO)
	if (alternative)
	{
		Sound_Stream* ss = new Sound_Stream(filename);
		m_soundStreams.push_back(ss);
		return reinterpret_cast<Sound*>(ss);
	}
	else
	{
		return reinterpret_cast<Sound*>(new Sound_Basic(new SoundFileReader(filename), m_soundPlayer));
	}
#else
	#error
#endif
}
Пример #3
0
void DL_Debug::Debug::AssertMessage(bool aCondition, const char *aFileName, int aLine, const char *aFunctionName, const wchar_t *aString)
{
	if (aCondition == false)
	{
		AssertMessage(aFileName, aLine, aFunctionName, aString);
	}
}
Пример #4
0
	void* readFile(FileLocalization fileLocalization, const char* filepath, size_t* outSize)
	{
#if defined(USES_WINDOWS8_DESKTOP) || defined(USES_WINDOWS_OPENGL)
		FILE* file = NULL;
		errno_t res = _wfopen_s(&file, getFullPathUnicode(fileLocalization, filepath).c_str(), L"rb");
		if (res != 0)
		{
			std::string mess = std::string("Missing file: \"")+filepath+'"';
			AssertMessage(false, mess.c_str());
		}
		fseek(file, 0, SEEK_END);
		size_t size = ftell(file);
		*outSize = size;
		rewind(file);
		unsigned char* data = new unsigned char[size];
		fread(data, size, 1, file);
		fclose(file);
		return data;
#elif defined(USES_WINDOWS8_METRO)
		if (!FileUtil::fileExists(fileLocalization, filepath))
		{
			std::stringstream sstr;
			sstr << "File '" << filepath << "' does not exist";
			AssertMessage(false, sstr.str().c_str());
		}
		BasicReaderWriter^ reader = ref new BasicReaderWriter(getStorageFolder(fileLocalization));
		// Load the raw texture data from disk and construct a subresource description that references it.
		auto data = reader->ReadData(getFilePath(filepath));
		*outSize = data->Length;
		unsigned char* dataCopy = new unsigned char[data->Length];
		memcpy(dataCopy, data->Data, data->Length);
		return dataCopy;
#elif defined(USES_LINUX)
		std::wstring fullpath = getFullPathUnicode(fileLocalization, filepath);
		FILE* file = fopen(Utils::convertWStringToString(fullpath).c_str(), "rb");
		fseek(file, 0, SEEK_END);
		size_t size = ftell(file);
		*outSize = size;
		rewind(file);
		unsigned char* data = new unsigned char[size];
		fread(data, size, 1, file);
		fclose(file);
		return data;
#else
	#error
#endif
	}
Пример #5
0
	void setCurrentDirectory(const char* path)
	{
#if defined(USES_WINDOWS8_METRO) || defined(USES_WINDOWS8_DESKTOP) || defined(USES_WINDOWS_OPENGL)
		std::string pathstr = path;
		AssertMessage(pathstr.find("..") != std::string::npos, "setCurrentDirectory: path not supported");
		if (pathstr[pathstr.size()-1]!='/') pathstr += '/';
		s_currentDirVirtual += pathstr;
#else
		chdir(path);
#endif
	}
static void TestWrongUser() {
  EscalateHelper *helper = NULL;
  GIOChannel *stdin_writer = NULL;
  GIOChannel *stdout_reader = NULL;
  GThread *helper_thread = NULL;

  EscalateTestSetIds(101, 0, 101, 0);
  EscalateTestMockAuthenticate(auth_wrong_user_prompts, PAM_AUTH_ERR);

  CreateHelper(&helper, &stdin_writer, &stdout_reader);
  helper_thread = RunHelperThread(helper);

  WriteMessage(stdin_writer,
               "(1, <(1, 0, 'janedoe', {3: @ms '/dev/pts/9000'})>)");
  AssertMessage(stdout_reader, "(4, <(4,)>)");

  JoinHelperThread(helper_thread);
  EscalateHelperFree(helper);
  g_io_channel_unref(stdin_writer);
  g_io_channel_unref(stdout_reader);
}
Пример #7
0
	void init(const std::vector<AchievementInfo>& achievementInfos) //const char *pchCmdLine, HINSTANCE hInstance, int nCmdShow)
	{
		g_AchievementInfosCopy = achievementInfos;
		for (size_t i = 0; i < achievementInfos.size(); ++i)
		{
			Achievement_t achievementData;
			achievementData.m_eAchievementID = i;
			achievementData.m_pchAchievementID = g_AchievementInfosCopy[i].id.c_str();
			strncpy(achievementData.m_rgchName, g_AchievementInfosCopy[i].name.c_str(), 128);
			strncpy(achievementData.m_rgchDescription, g_AchievementInfosCopy[i].description.c_str(), 128);
			achievementData.m_bAchieved = false;
			achievementData.m_iIconImage = 0;
			g_Achievements.push_back(achievementData);
		}

		if (SteamAPI_RestartAppIfNecessary(k_uAppIdInvalid))
		{
			// if Steam is not running or the game wasn't started through Steam, SteamAPI_RestartAppIfNecessary starts the
			// local Steam client and also launches this game again.

			// Once you get a public Steam AppID assigned for this game, you need to replace k_uAppIdInvalid with it and
			// removed steam_appid.txt from the game depot.

			AssertMessage(false, "SteamAPI_RestartAppIfNecessary failed");
		}

		// Init Steam CEG
		if (!Steamworks_InitCEGLibrary())
		{
			Utils::sleepMs(1000);
			if (!Steamworks_InitCEGLibrary()) // try twice - it may be a glitch in the network?
			{
				AssertMessage(false, "Steam must be running to play this game (InitDrmLibrary() failed).");
			}
		}

		// Initialize SteamAPI, if this fails we bail out since we depend on Steam for lots of stuff.
		// You don't necessarily have to though if you write your code to check whether all the Steam
		// interfaces are NULL before using them and provide alternate paths when they are unavailable.
		//
		// This will also load the in-game steam overlay dll into your process.  That dll is normally
		// injected by steam when it launches games, but by calling this you cause it to always load,
		// even when not launched via steam.
		if (!SteamAPI_Init())
		{
			Utils::sleepMs(1000);
			if (!SteamAPI_Init())
			{
				AssertMessage(false, "Steam must be running to play this game (SteamAPI_Init() failed).\n");
			}
		}

		// Create the SteamAchievements object if Steam was successfully initialized
		g_SteamAchievements = new CSteamAchievements(&g_Achievements[0], g_Achievements.size());


		bool res = g_SteamAchievements->RequestStats();
		if (!res)
		{
			Utils::sleepMs(1000);
			res = g_SteamAchievements->RequestStats();
			if (!res)
			{
				AssertMessage(false, "Could not get stats from Steam.\nPlease check that your Internet connection is working correctly and that Steam is up.\n");
			}
		}


		// set our debug handler
		SteamClient()->SetWarningMessageHook(&SteamAPIDebugTextHook);

		// Tell Steam where it's overlay should show notification dialogs, this can be top right, top left,
		// bottom right, bottom left. The default position is the bottom left if you don't call this.
		// Generally you should use the default and not call this as users will be most comfortable with
		// the default position.  The API is provided in case the bottom right creates a serious conflict
		// with important UI in your game.
		SteamUtils()->SetOverlayNotificationPosition(k_EPositionTopRight);

		// Ensure that the user has logged into Steam. This will always return true if the game is launched
		// from Steam, but if Steam is at the login prompt when you run your game from the debugger, it
		// will return false.
		if (!SteamUser()->BLoggedOn())
		{
			Utils::sleepMs(1000);
			if (!SteamUser()->BLoggedOn())
			{
				AssertMessage(false, "Steam user must be logged in to play this game (SteamUser()->BLoggedOn() returned false).\n");
			}
		}

		// We are going to use the controller interface, initialize it, which is a seperate step as it
		// create a new thread in the game proc and we don't want to force that on games that don't
		// have native Steam controller implementations

#ifdef USES_LINUX
		std::string rgchCWDstr = Utils::convertWStringToString(Utils::getCurrentDirectoryUnicode(), true);
		const char* rgchCWD = rgchCWDstr.c_str();
#else
		char rgchCWD[1024];
		_getcwd( rgchCWD, sizeof( rgchCWD ) );
#endif

		char rgchFullPath[1024];
#if defined(_WIN32)
		_snprintf(rgchFullPath, sizeof(rgchFullPath), "%s\\%s", rgchCWD, "controller.vdf");//.c_str()
#elif defined(OSX)
		// hack for now, because we do not have utility functions available for finding the resource path
		// alternatively we could disable the SteamController init on OS X
		_snprintf(rgchFullPath, sizeof(rgchFullPath), "%s/steamworksexample.app/Contents/Resources/%s", rgchCWD, "controller.vdf");
#else
		_snprintf(rgchFullPath, sizeof(rgchFullPath), "%s/%s", rgchCWD, "controller.vdf");
#endif
		if (!SteamController()->Init(rgchFullPath))
		{
			AssertMessage(false, "Steam Controller Init failed. Is controller.vdf in the current working directory?\n");
		}

		/*bool bUseVR = SteamUtils()->IsSteamRunningInVR();
		const char *pchServerAddress, *pchLobbyID;
		ParseCommandLine(pchCmdLine, &pchServerAddress, &pchLobbyID, &bUseVR);*/

		// do a DRM self check
		Steamworks_SelfCheck();

		// init VR before we make the window

		// Construct a new instance of the game engine
		// bugbug jmccaskey - make screen resolution dynamic, maybe take it on command line?
		/*IGameEngine *pGameEngine =
#if defined(_WIN32)
			new CGameEngineWin32(hInstance, nCmdShow, 1024, 768, bUseVR);
#elif defined(OSX)
			CreateGameEngineOSX();
#elif defined(SDL)
			CreateGameEngineSDL(bUseVR);
#else
#error	Need CreateGameEngine()
#endif*/
	}
Пример #8
0
//------------------------------------------------------------------------------
//--------------------------------------
// Object proper...
//--------------------------------------
//
Surface* 
Surface::create(HWND        io_clientWnd,
                const Int32 in_width,
                const Int32 in_height)
{
   // Must return a new OpenGL::Surface* of resolution closest to in_w/h.
   //  Should also activate the device.
   //
   AssertFatal(io_clientWnd != NULL, "No client window handle");

   Surface* pRetSurf = new Surface;

#ifndef DEBUG
   BOOL   test    = TRUE;
   bool   found   = false;
   UInt32 modeNum = 0;
   DEVMODE devMode;

   while (test == TRUE) {
      memset(&devMode, 0, sizeof(devMode));
      devMode.dmSize = sizeof(devMode);
      test = EnumDisplaySettings(NULL, modeNum, &devMode);
      if (devMode.dmPelsWidth        == (UInt32)in_width  &&
          devMode.dmPelsHeight       == (UInt32)in_height) {
         found = true;
      }

      modeNum++;
   }

   if (found == false) {
      delete pRetSurf;
      return NULL;
   }

   // Change the window position
   AssertMessage(false, avar("Changing window style (%d, %d)", in_width, in_height));
   GetWindowRect(io_clientWnd, &pRetSurf->m_oldWindowRect);
   LONG style = GetWindowLong(io_clientWnd, GWL_STYLE);
   style &= ~(WS_CAPTION | WS_SYSMENU | WS_THICKFRAME);
   SetWindowLong(io_clientWnd, GWL_STYLE, style);

   LONG exStyle = GetWindowLong(io_clientWnd, GWL_EXSTYLE);
   exStyle |= WS_EX_TOPMOST;
   SetWindowLong(io_clientWnd, GWL_EXSTYLE, exStyle);
   BOOL posSuccess = SetWindowPos(io_clientWnd, 0, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED);
   AssertFatal(posSuccess == TRUE, "Error setting pos");

   // Annnnd, set the new display mode.  Desktop icons?
   //
   memset(&devMode, 0, sizeof(devMode));
   devMode.dmSize = sizeof(devMode);
   devMode.dmPelsWidth  = in_width;
   devMode.dmPelsHeight = in_height;
   devMode.dmFields = DM_PELSWIDTH  |
                      DM_PELSHEIGHT;

#if 1
   AssertMessage(false, avar("Changing display settings: (%d, %d)", devMode.dmPelsWidth, devMode.dmPelsHeight));
   ChangeDisplaySettings(&devMode, CDS_FULLSCREEN);
   VidModeChecker::sm_theInstance.changedDisplaySettings();
#endif

   SetForegroundWindow(io_clientWnd);
   posSuccess = SetWindowPos(io_clientWnd, HWND_TOPMOST, 0, 0, in_width, in_height, SWP_FRAMECHANGED);
   AssertFatal(posSuccess == TRUE, "Error setting pos");
   pRetSurf->m_windowStyleChanged = true;
#endif

   pRetSurf->m_hWnd = io_clientWnd;
   pRetSurf->m_hDC = GetDC(pRetSurf->m_hWnd);
   if (pRetSurf->m_hDC == NULL) {
      AssertWarn(0, "Unable to get a DC for the window");
      delete pRetSurf;
      return NULL;
   }

   // Set the Pixel format, first retrieving the old format
   //
   pRetSurf->m_oldPixelFormat = GetPixelFormat(pRetSurf->m_hDC);
   DescribePixelFormat(pRetSurf->m_hDC, pRetSurf->m_oldPixelFormat,
                       sizeof(PIXELFORMATDESCRIPTOR),
                       &pRetSurf->m_oldPixelFormatDescriptor);

   int chosenPixelFormat;
   PIXELFORMATDESCRIPTOR chosenPFD;
   if (pRetSurf->choosePixelFormat(chosenPixelFormat,
                                   chosenPFD,
                                   pRetSurf->m_hWnd,
                                   pRetSurf->m_hDC) == false) {
      AssertWarn(0, "Unable to choose a pixel format");
      delete pRetSurf;
      return NULL;
   }

   BOOL spSuccess = SetPixelFormat(pRetSurf->m_hDC,
                                   chosenPixelFormat,
                                   &chosenPFD);
   if (spSuccess != TRUE) {
      AssertWarn(0, "Unable to set the pixel format");
      delete pRetSurf;
      return NULL;
   }

   // Create the HGLRC
   //
   pRetSurf->m_hGLRC = wglCreateContext(pRetSurf->m_hDC);
   if (pRetSurf->m_hGLRC == NULL) {
      AssertWarn(0, "Unable to create a GL Render context");
      delete pRetSurf;
      return NULL;
   }

   BOOL mcSuccess = wglMakeCurrent(pRetSurf->m_hDC, pRetSurf->m_hGLRC);
   if (mcSuccess != TRUE) {
      AssertWarn(0, "Unable to make the GL Render context current");
      delete pRetSurf;
      return NULL;
   }
   pRetSurf->m_glrcMadeCurrent = true;

   // Retreive the strings associated with this driver, they are useful
   //  for debugging and such...
   //
   const char* pVendor     = (const char*)glGetString(GL_VENDOR);
   const char* pRenderer   = (const char*)glGetString(GL_RENDERER);
   const char* pVersion    = (const char*)glGetString(GL_VERSION);
   const char* pExtensions = (const char*)glGetString(GL_EXTENSIONS);

   if (pVendor != NULL) {
      pRetSurf->m_pVendorString = new char[strlen(pVendor) + 1];
      strcpy(pRetSurf->m_pVendorString, pVendor);
   }
   if (pRenderer != NULL) {
      pRetSurf->m_pRendererString = new char[strlen(pRenderer) + 1];
      strcpy(pRetSurf->m_pRendererString, pRenderer);
   }
   if (pVersion != NULL) {
      pRetSurf->m_pVersionString = new char[strlen(pVersion) + 1];
      strcpy(pRetSurf->m_pVersionString, pVersion);
   }
   if (pExtensions != NULL) {
      pRetSurf->m_pExtensionsString = new char[strlen(pExtensions) + 1];
      strcpy(pRetSurf->m_pExtensionsString, pExtensions);
   }

   // Allocate our vertex arrays...
   //
   pRetSurf->m_pVertexArray    = new DGLVertex4F[sm_maxNumVertices];
   pRetSurf->m_pColorArray     = new DGLColor4F[sm_maxNumVertices];
   pRetSurf->m_pTexCoord0Array = new DGLTexCoord4F[sm_maxNumVertices];
   pRetSurf->m_pHazeStoreArray = new DGLHazeCoordF[sm_maxNumVertices];

   pRetSurf->surfaceWidth  = in_width;
   pRetSurf->surfaceHeight = in_height;

   // Create the texture/handle cache...
   //
   pRetSurf->m_pTextureCache = new TextureCache(pRetSurf);
   pRetSurf->m_pHandleCache  = new HandleCache(2048, 2153);

   // Set up our default state...
   //
   pRetSurf->setFillMode(GFX_FILL_CONSTANT);
   pRetSurf->setFillColor(&ColorF(0, 0, 0));
   pRetSurf->setAlphaSource(GFX_ALPHA_NONE);
   pRetSurf->setShadeSource(GFX_SHADE_NONE);
   pRetSurf->setHazeSource(GFX_HAZE_NONE);
   pRetSurf->setTextureWrap(true);
   pRetSurf->setTransparency(false);

   glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

   // We're ready to go...
   //
   return pRetSurf;
}
Пример #9
0
Surface::~Surface()
{
   AssertFatal(g_surfaceActive == this, "We're not the active surface?");
   g_surfaceActive = NULL;
   g_oglDisableLightUpdates = false;

   // Remove our texture cache...
   //
   delete m_pHandleCache;
   m_pHandleCache = NULL;

   if (m_pTextureCache != NULL)
      m_pTextureCache->flushCache();
   delete m_pTextureCache;
   m_pTextureCache = NULL;


   // Clear out our vertex indices...
   //
   m_currVertexIndex = 0;
   delete [] m_pHazeStoreArray;
   m_pHazeStoreArray = NULL;
   delete [] m_pTexCoord0Array;
   m_pTexCoord0Array = NULL;
   delete [] m_pColorArray;
   m_pColorArray = NULL;
   delete [] m_pVertexArray;
   m_pVertexArray = NULL;

   if (m_hGLRC != NULL) {
      if (m_hDC != NULL) {
         BOOL success = wglMakeCurrent(m_hDC, NULL);
         AssertWarn(success == TRUE, "Couldn't clear the hGLRC?");
      }
      m_glrcMadeCurrent = false;
      BOOL success = wglDeleteContext(m_hGLRC);
      AssertWarn(success == TRUE, "Couldn't delete the hGLRC?");
   }

   // Reset the pixel format...
   //
   if (m_oldPixelFormat != -1) {
      AssertFatal(m_hDC != NULL, "old pixel format with no DC?");

      BOOL success = SetPixelFormat(m_hDC,
                                    m_oldPixelFormat,
                                    &m_oldPixelFormatDescriptor);
      AssertWarn(success == TRUE, "Couldn't set the pixel format to 0?");
   }

   if (m_hDC != NULL && m_hWnd != NULL) {
      ReleaseDC(m_hWnd, m_hDC);
   }

   delete [] m_pVendorString;
   delete [] m_pRendererString;
   delete [] m_pVersionString;
   delete [] m_pExtensionsString;

   if (m_windowStyleChanged == true) {
      AssertMessage(false, "Resetting window style");
      // Reset the window style and position
      //
      LONG style = GetWindowLong(m_hWnd, GWL_STYLE);
      style |= (WS_CAPTION | WS_SYSMENU | WS_THICKFRAME);
      SetWindowLong(m_hWnd, GWL_STYLE, style);

      LONG exStyle = GetWindowLong(m_hWnd, GWL_EXSTYLE);
      exStyle &= ~(WS_EX_TOPMOST);
      SetWindowLong(m_hWnd, GWL_EXSTYLE, exStyle);

      SetForegroundWindow(m_hWnd);
      SetWindowPos(m_hWnd, HWND_TOP,
                   m_oldWindowRect.left,
                   m_oldWindowRect.top,
                   m_oldWindowRect.right,
                   m_oldWindowRect.bottom,
                   SWP_FRAMECHANGED);
   }

   VidModeChecker::sm_theInstance.resetDisplaySettings();

   m_hGLRC          = NULL;
   m_hDC            = NULL;
   m_hWnd           = NULL;
   m_oldPixelFormat = -1;

   m_pVendorString        =
      m_pRendererString   =
      m_pVersionString    =
      m_pExtensionsString = NULL;
}