_MEMBER_FUNCTION_IMPL(GUIElement, constructor)
{
	const char * name;
	sq_getstring(pVM, -1, &name);
	String szName = name;

	if(szName.IsEmpty())
		_SET_RELEASE_HOOK(GUIElement);

	// Get our GUI instance
	CGUI * pGUI = g_pClient->GetGUI();

	try
	{
		pGUI->GetWindowManager()->getWindow(szName.C_String());
	}
	catch(CEGUI::Exception &e)
	{
		e;
		_SET_RELEASE_HOOK(GUIElement);
	}

	CEGUI::Window * pWindow = pGUI->GetWindowManager()->getWindow(szName.C_String());
	if(!pWindow || SQ_FAILED(sq_setinstance(pVM, pWindow)))
	{
		CLogFile::Printf("Can't create GUIElement.");
		sq_pushbool(pVM, false);
		return 1;
	}

	SubscribeGuiEvents(pWindow);

	sq_pushbool(pVM, true);
	return 1;
}
// GUIImage
_MEMBER_FUNCTION_IMPL(GUIImage, constructor)
{
	const char * filename;
	sq_getstring(pVM, -1, &filename);

	// check file size
	/*FILE* pFile = fopen(filename, "rb");
	fseek(pFile, 0L, SEEK_END);
	int len = ftell(pFile);
	if(len == 0) {
		sq_pushbool(pVM, false);
		fclose(pFile);
		return 1;
	}
	fclose(pFile);*/

	// Get our GUI
	CGUI * pGUI = g_pClient->GetGUI();

	String szName = pGUI->GetUniqueName();

	// Try to load the image
	try
	{

		CEGUI::ImagesetManager::getSingleton().createFromImageFile(szName.C_String(), filename, "resources");
		CGUIStaticImage * pImage = pGUI->CreateGUIStaticImage(CEGUI::String(szName.C_String()));
		
		pImage->setProperty("FrameEnabled", "false");
		pImage->setProperty("BackgroundEnabled", "false");
		pImage->setProperty("Image", String("set:%s image:full_image", szName.C_String()).C_String());

		if(!pImage || SQ_FAILED(sq_setinstance(pVM, pImage)))
		{
			CLogFile::Printf("Can't create GUIImage.");
			sq_pushbool(pVM, false);
			return 1;
		}

		//_SET_RELEASE_HOOK(GUIElement);
		CClientScriptManager * pClientScriptManager = g_pClient->GetClientScriptManager();
		pClientScriptManager->GetGUIManager()->Add(pImage, pClientScriptManager->GetScriptingManager()->Get(pVM));

		SubscribeGuiEvents(pImage);

		pImage->setVisible(true);
		sq_pushbool(pVM, true);
		return 1;
	}
	catch(CEGUI::Exception e)
	{
		// Failed to load, might not exist
		CLogFile::Printf("Can't create GUIImage (%s does not exist)", filename);
		sq_pushbool(pVM, false);
		return 1;
	}
}
Beispiel #3
0
void CNetworkManager::Startup(int iPort, int iMaxPlayers, String strPassword, String strHostAddress)
{
    // Start up the net server
    m_pNetServer->Startup(iPort, iMaxPlayers, strHostAddress.C_String());

    // Do we have a password?
    if(!strPassword.IsEmpty())
    {
        // Set the RakServer password
        m_pNetServer->SetPassword(strPassword.C_String());
    }

    // Register the packets
    m_pServerPacketHandler->Register();

    // Register the rpcs
    m_pServerRPCHandler->Register();
}
Beispiel #4
0
bool CServer::GetConfigBoolean(String strKey, bool bDefaultValue)
{
	bool bValue = false;

	if(!(g_pConfig && g_pConfig->GetValueAsBoolean(strKey, bDefaultValue, &bValue)))
	{
		CLogFile::Printf("Failed to get '%s' value from config, defaulting to '%s'", strKey.C_String(), (bDefaultValue ? "true" : "false"));
	}

	return bValue;
}
Beispiel #5
0
float CServer::GetConfigFloat(String strKey, float fDefaultValue)
{
	float fValue = 0.0f;

	if(!(g_pConfig && g_pConfig->GetValueAsFloat(strKey, fDefaultValue, &fValue)))
	{
		CLogFile::Printf("Failed to get '%s' value from config, defaulting to '%f'", strKey.C_String(), fDefaultValue);
	}

	return fValue;
}
Beispiel #6
0
int CServer::GetConfigInteger(String strKey, int iDefaultValue)
{
	int iValue = 0;

	if(!(g_pConfig && g_pConfig->GetValueAsInteger(strKey, iDefaultValue, &iValue)))
	{
		CLogFile::Printf("Failed to get '%s' value from config, defaulting to '%d'", strKey.C_String(), iDefaultValue);
	}

	return iValue;
}
Beispiel #7
0
String CServer::GetConfigString(String strKey, String strDefaultValue)
{
	String strValue;

	if(!(g_pConfig && g_pConfig->GetValueAsString(strKey, strDefaultValue, &strValue)))
	{
		CLogFile::Printf("Failed to get '%s' value from config, defaulting to '%s'", strKey.C_String(), strDefaultValue.C_String());
	}

	return strValue;
}
void CServerRPCHandler::InitialData(CBitStream * pBitStream, CPlayerSocket senderSocket)
{
	CLogFile::Printf("Got InitialData RPC from player %d", senderSocket.playerId);

	// Ensure we have a valid bitstream
	if(!pBitStream)
	{
		CLogFile::Printf("Warning: Invalid bitstream for InitialData RPC");
		return;
	}

	// Read the data they sent us
	String strName;
	
	// Read the name
	if(!pBitStream->Read(strName))
		return;

	// Add them to the player manager
	g_pServer->GetPlayerManager()->Add(senderSocket.playerId, strName, senderSocket.GetSerial());

	// Construct the initial data bit stream
	CBitStream bitStream;

	// Write their player id
	bitStream.WriteCompressed(senderSocket.playerId);

	// Send the initial data bit stream
	g_pServer->GetNetworkManager()->RPC(RPC_INITIAL_DATA, &bitStream, PRIORITY_HIGH, RELIABILITY_RELIABLE_ORDERED, senderSocket.playerId, false);

	// Send them all current players
	g_pServer->GetPlayerManager()->HandlePlayerJoin(senderSocket.playerId);

	// Send them all current vehicles
	g_pServer->GetVehicleManager()->HandlePlayerJoin(senderSocket.playerId);

	// Spawn them for all current players
	g_pServer->GetPlayerManager()->Get(senderSocket.playerId)->SpawnForWorld();

	CLogFile::Printf("Player %d has joined the game (Name: %s)", senderSocket.playerId, strName.C_String());
}
Beispiel #9
0
bool CHttpClient::ParseHeaders(String& strBuffer, int& iBufferSize)
{
	// Find the header size, testing code, but should work
	mg_request_info info;
	
	char* buf = new char[iBufferSize];
	memcpy(buf, strBuffer.C_String(), iBufferSize);
	parse_http_response(buf, strBuffer.GetLength(), &info);
	
	String buf_header;
	int iHeaderSize = 0;
	for(int i = 0; i < info.num_headers; ++i)
	{
		buf_header.AppendF("%s: %s\r\n", info.http_headers[i].name, info.http_headers[i].value);
	}

	iHeaderSize = buf_header.GetLength();
	iHeaderSize += (info.request_method != NULL ? strlen(info.request_method) : 0) + (info.uri != NULL ? strlen(info.uri) : 0) + (info.http_version != NULL ? strlen(info.http_version) : 0) + strlen("\r\n\r\n\r\n");
	iBufferSize -= iHeaderSize;
	strBuffer.Erase(0, iHeaderSize);
	m_headerMap["HeaderSize"] = iHeaderSize;


	// ADAMIX/JENKSTA: commented out this code because doesn't work properly. Are we really need to parse headers?

	/*// Ignore all initial whitespace
	unsigned int uiWhiteSpace = 0;

	for(unsigned int i = 0; i < (unsigned int)iBufferSize; i++)
	{
		// Is this whitespace?
		if(strBuffer[i] == ' ')
		{
			// Increment the whitespace amount
			uiWhiteSpace++;
			continue;
		}

		// Finished
		break;
	}

	// Remove whitespace
	if(uiWhiteSpace > 0)
		strBuffer.Erase(0, uiWhiteSpace);

	// Ignore the version, status code and status message
	// TODO: Use this information?
	// Will be in format 'HTTP/1.0 200 OK\r\n'
	unsigned int uiIgnore = strBuffer.Find("\r\n");

	if(uiIgnore == String::nPos)
		return false;

	strBuffer.Erase(0, (uiIgnore + 2));
	iBufferSize -= (uiIgnore + 2);

	// Find all headers
	unsigned int uiContentLength = String::nPos;
	unsigned int uiNameSplit;
	unsigned int uiValueSplit;

	while((uiNameSplit = strBuffer.Find(": ")) != String::nPos)
	{
		// Do we have a content length?
		if(uiContentLength != String::nPos)
		{
			// Get the content start
			unsigned int uiContentStart = (iBufferSize - uiContentLength);

			// Is the find over the content start?
			if(uiNameSplit >= uiContentStart)
				break;
		}

		// Find the value end
		uiValueSplit = strBuffer.Find("\r\n");

		// Did we not find a value end?
		if(uiValueSplit == String::nPos)
			return false;

		// Get the header name
		String strName = strBuffer.SubStr(0, uiNameSplit);

		// If this is an accept-ranges header get the value from the next header
		// jenksta: not sure if this is right, but this is how it works with 'accept-ranges: bytes'
		// in mongoose
		if(!strName.ICompare("accept-ranges"))
		{
			// Find the value end
			uiValueSplit = strBuffer.Find("\r\n", (uiValueSplit + 2));

			// Did we not find a value end?
			if(uiValueSplit == String::nPos)
				return false;
		}

		// Get the header value
		String strValue = strBuffer.SubStr((uiNameSplit + 2), (uiValueSplit - (uiNameSplit + 2)));

		// Add the header to the header map
		m_headerMap[strName] = strValue;

		// Erase the header from the buffer
		strBuffer.Erase(0, (uiValueSplit + 2));
		iBufferSize -= (uiValueSplit + 2);

		// Is this the content length header?
		if(!strName.ICompare("content-length"))
		{
			// Set the content length
			uiContentLength = strValue.ToInteger();
		}
	}

	// Did we not get any headers?
	if(m_headerMap.empty())
		return false;
	*/
	// Success
	return true;
}
// getServerPassword()
SQInteger CServerNatives::GetPassword(SQVM * pVM)
{
	String sPass = CVAR_GET_STRING("password");
	sq_pushstring(pVM, sPass.C_String(), sPass.GetLength());
	return 1;
}
Beispiel #11
0
// getServerPassword()
int CServerNatives::GetPassword(lua_State * pVM)
{
	String sPass = CVAR_GET_STRING("password");
	script_pushlstring(pVM, sPass.C_String(), sPass.GetLength());
	return 1;
}
Beispiel #12
0
size_t String::Substitute(const String strString, const String strSubstitute)
{
	return Substitute(strString.C_String(), strSubstitute);
}
Beispiel #13
0
void CServerRPCHandler::ChatInput(CBitStream * pBitStream, CPlayerSocket senderSocket)
{
	CLogFile::Printf("Got ChatInput RPC from player %d", senderSocket.playerId);

	// Ensure we have a valid bitstream
	if(!pBitStream)
	{
		CLogFile::Printf("Warning: Invalid bitstream for ChatInput RPC");
		return;
	}

	// Get the player pointer
	CPlayer * pPlayer = g_pServer->GetPlayerManager()->Get(senderSocket.playerId);

	// Is the player pointer valid?
	if(pPlayer)
	{
		// Read the data they sent us
		bool bIsCommand;
		String strInput;

		// Read if its a command or not
		bIsCommand = pBitStream->ReadBit();

		// Read the input
		if(!pBitStream->Read(strInput))
			return;

		// Prepare the event arguments
		CSquirrelArguments arguments;
		arguments.push(strInput);

		// Is it not a command?
		if(!bIsCommand)
		{
			// Trigger the event, if it is canceled, don't output the line to other players
			if(pPlayer->CallEvent("playerChat", &arguments))
			{
				// Construct the chat input bit stream
				CBitStream bitStream;

				// Write the player id
				bitStream.WriteCompressed(senderSocket.playerId);

				// Write the input
				bitStream.Write(strInput);

				// Send it to all other players
				g_pServer->GetNetworkManager()->RPC(RPC_CHAT_INPUT, &bitStream, PRIORITY_HIGH, RELIABILITY_RELIABLE_ORDERED, INVALID_ENTITY_ID, true);
			}
		}
		else
		{
			// Trigger the event
			pPlayer->CallEvent("playerCommand", &arguments);
		}

		CLogFile::Printf("Recieved chat input from player %d (Command?: %s, Input: %s)", senderSocket.playerId, bIsCommand ? "Yes" : "No", strInput.C_String());
	}
}