Пример #1
0
int main(int argc, char** argv)
{
	if (argc > 1)
	{
		ipAndSuch = argv[1];

		if (argc > 2)
		{
			port = atoi(argv[2]);
		}
	}

	CSteamAPILoader* loader   = new CSteamAPILoader();
	CreateInterfaceFn factory = loader->Load();

	BGetCallback          = static_cast<Steam_BGetCallbackFn>    (loader->GetSteamClientModule()->GetSymbol("Steam_BGetCallback"));
	FreeLastCallback      = static_cast<Steam_FreeLastCallbackFn>(loader->GetSteamClientModule()->GetSymbol("Steam_FreeLastCallback"));
	IClientEngine *client = static_cast<IClientEngine *>         (factory(CLIENTENGINE_INTERFACE_VERSION, NULL));

	HSteamPipe pipe = client->CreateSteamPipe();
	HSteamUser user = client->ConnectToGlobalUser(pipe);

	IClientFriends *clientfriends = static_cast<IClientFriends*>(client->GetIClientFriends(user, pipe, CLIENTFRIENDS_INTERFACE_VERSION));
	IClientUser *clientuser       = static_cast<IClientUser*>   (client->GetIClientUser(user, pipe, CLIENTUSER_INTERFACE_VERSION));

	cout << "Now connected to steam and awaiting callbacks!" << endl;

	while(true)
	{
		CallbackMsg_t callBack;
		if (BGetCallback( pipe, &callBack ) )
		{
			switch (callBack.m_iCallback)
			{
			case ChatRoomMsg_t::k_iCallback:
			case 810: // Chat room callback
                {
				    ChatRoomMsg_t Info = *(ChatRoomMsg_t *)callBack.m_pubParam;

				    if (Info.m_ulSteamIDUser == clientuser->GetSteamID())
					    break;
				
				    CSteamID userID;
				    string userName = clientfriends->GetFriendPersonaName(Info.m_ulSteamIDUser);
				    EChatEntryType entry = k_EChatEntryTypeInvalid;

                    char* temp = new char[4096];
				    clientfriends->GetChatRoomEntry(Info.m_ulSteamIDChat, Info.m_iChatID, &userID, temp, 4096, &entry);
                    std::string message = temp;
                    delete[] temp;

				    if (entry != k_EChatEntryTypeChatMsg && entry != k_EChatEntryTypeEmote)
						    break;

				    cout << "[Group] " << userName << " said something!" << endl;
				
                    bool foundOny = (ci_find_substr<string>(message, "ony") != -1);

					if (!foundOny && entry == k_EChatEntryTypeChatMsg)
					{
						RunBotCommand(Info.m_ulSteamIDUser, Message_Tell, message, userName, Chat_Group);
					}
                    
                    if (!foundOny)
                        break;
				
				    string response = RunBotCommand(Info.m_ulSteamIDUser, Message_Interact, message, userName, Chat_Group);

				    if(response.length() == 0)
                    {
                        cout << " !!Bot didn't respond!!" << endl;
					    break;
                    }
                    else if (response.front() == '!')
                    {
                        cout << " !" << response << "!" << endl;
                        break;
                    }
                    
				    EChatEntryType toSend = k_EChatEntryTypeChatMsg;
				    if (response.front() == '*' && response.back() == '*')
				    {
					    toSend = k_EChatEntryTypeEmote;
					    response.erase(response.begin());
					    response.erase(response.end()-1);
				    }

				    clientfriends->SendChatMsg(Info.m_ulSteamIDChat, toSend, response.c_str(), response.length()+1);

				    break;
                }

		    case 805:
			case FriendChatMsg_t::k_iCallback:
                {
				    FriendChatMsg_t Info = *(FriendChatMsg_t *)callBack.m_pubParam;

				    if (Info.m_ulSender == clientuser->GetSteamID())
					    break;

				    EChatEntryType entry = k_EChatEntryTypeInvalid;

                    char* temp = new char[4096];
				    clientfriends->GetFriendMessage(Info.m_ulReceiver, Info.m_iChatID, temp, 4096, &entry);
                    std::string message = temp;
                    delete[] temp;

				    if (entry != k_EChatEntryTypeChatMsg)
					    break;

                    string userName = clientfriends->GetFriendPersonaName(Info.m_ulSender);

				    cout << "[Friend] " << userName << " said something!" << endl;

				    string response = RunBotCommand(Info.m_ulSender, Message_Interact, message, userName, Chat_Private);

                    if(response.length() == 0)
                    {
                        cout << " !!Bot didn't respond!!" << endl;
					    break;
                    }
                    else if (response.front() == '!')
                    {
                        cout << " !" << response << "!" << endl;
                        break;
                    }

				    clientfriends->SendMsgToFriend(Info.m_ulSender, k_EChatEntryTypeChatMsg, response.c_str(), response.length()+1);
				    break;
                }

			default:
                {
#ifdef _DEBUG
                    cout << "Uncaught callback " << callBack.m_iCallback << " (" << GetCallbackType(callBack.m_iCallback) << ")" << endl;
#endif
				    break;
                }
			}

			FreeLastCallback(pipe);
		}

		sf::Sleep(10);
	}

	return 0;
}
Пример #2
0
	virtual void ReleaseUser(HSteamPipe hSteamPipe, HSteamUser hUser) override
	{
		return m_baseEngine->ReleaseUser(hSteamPipe, hUser);
	}
Пример #3
0
	virtual bool IsValidHSteamUserPipe(HSteamPipe hSteamPipe, HSteamUser hUser) override
	{
		return m_baseEngine->IsValidHSteamUserPipe(hSteamPipe, hUser);
	}
Пример #4
0
	virtual HSteamUser CreateLocalUser(HSteamPipe* phSteamPipe, EAccountType eAccountType) override
	{
		return m_baseEngine->CreateLocalUser(phSteamPipe, eAccountType);
	}
Пример #5
0
	virtual void CreatePipeToLocalUser(HSteamUser hSteamUser, HSteamPipe* phSteamPipe) override
	{
		return m_baseEngine->CreatePipeToLocalUser(hSteamUser, phSteamPipe);
	}
Пример #6
0
	virtual HSteamUser ConnectToGlobalUser(HSteamPipe hSteamPipe) override
	{
		return m_baseEngine->ConnectToGlobalUser(hSteamPipe);
	}
Пример #7
0
	virtual HSteamUser CreateGlobalUser(HSteamPipe* phSteamPipe) override
	{
		return m_baseEngine->CreateGlobalUser(phSteamPipe);
	}
Пример #8
0
	virtual bool BReleaseSteamPipe(HSteamPipe hSteamPipe) override
	{
		return m_baseEngine->BReleaseSteamPipe(hSteamPipe);
	}
Пример #9
0
	virtual HSteamPipe CreateSteamPipe() override
	{
		return m_baseEngine->CreateSteamPipe();
	}
Пример #10
0
bool CLogger::InitSteam()
{
	CreateInterfaceFn steam3Factory = m_steamLoader.GetSteam3Factory();
	if(!steam3Factory)
		return false;

	m_pSteamClient = (ISteamClient012*)steam3Factory(STEAMCLIENT_INTERFACE_VERSION_012, NULL);
	if(!m_pSteamClient)
		return false;

	m_hPipe = m_pSteamClient->CreateSteamPipe();
	if(!m_hPipe || m_hPipe == -1)
		return false;

	// Steamworks likes to deadlock if we create the pipe while Steam is starting
	// Which leads us to use this ugly hack.
	m_pSteamClient->BReleaseSteamPipe(m_hPipe);
	wxMilliSleep(5000);

	m_hPipe = m_pSteamClient->CreateSteamPipe();
	if(!m_hPipe || m_hPipe == -1)
		return false;

	m_hUser = m_pSteamClient->ConnectToGlobalUser(m_hPipe);
	if(!m_hUser)
		return false;

	m_pSteamFriends = (ISteamFriends013*)m_pSteamClient->GetISteamFriends(m_hUser, m_hPipe, STEAMFRIENDS_INTERFACE_VERSION_013);
	if(!m_pSteamFriends)
		return false;

	m_pSteamUser = (ISteamUser016*)m_pSteamClient->GetISteamUser(m_hUser, m_hPipe, STEAMUSER_INTERFACE_VERSION_016);
	if(!m_pSteamUser)
		return false;

	wxGetApp().SetTrayIcon(CApp::k_EIconNormal);
	wxGetApp().Message(_("Connected to Steam."));

	if(m_bUseClientInterfaces)
	{
		IClientEngine* pClientEngine = (IClientEngine*)steam3Factory(CLIENTENGINE_INTERFACE_VERSION, NULL);
		if(!pClientEngine)
		{
			wxGetApp().SetTrayIcon(CApp::k_EIconWarning, _("Group chat logging and Nickname support are disabled"));
			wxGetApp().Warning(_("Unable to get IClientEngine interface,\nGroup chat logging and Nickname support are disabled."));
			return true;
		}

		m_pClientFriends = pClientEngine->GetIClientFriends(m_hUser, m_hPipe, CLIENTFRIENDS_INTERFACE_VERSION);
		if(!m_pClientFriends)
		{
			wxGetApp().SetTrayIcon(CApp::k_EIconWarning, _("Group chat logging and Nickname support are disabled"));
			wxGetApp().Warning(_("Unable to get IClientFriends interface,\nGroup chat logging and Nickname support are disabled."));
			return true;
		}

		m_pGetChatRoomEntry = (int32 (__thiscall *)(IClientFriends *,CSteamID, int32, CSteamID *, void *, int32, EChatEntryType *)) FindSteamFunction("GetChatRoomEntry");
		if(!m_pGetChatRoomEntry)
		{
			wxGetApp().SetTrayIcon(CApp::k_EIconWarning, _("Group chat logging is disabled"));
			wxGetApp().Warning(_("Unable to find GetChatRoomEntry,\nGroup chat logging is disabled."));
		}
		
		m_pGetChatRoomName = (const char *(__thiscall *)(IClientFriends *, CSteamID)) FindSteamFunction("GetChatRoomName");
		if(!m_pGetChatRoomName)
		{
			wxGetApp().SetTrayIcon(CApp::k_EIconWarning, _("{Name} variable is disabled"));
			wxGetApp().Warning(_("Unable to find GetChatRoomName,\nThe {Name} variable won't work for chat rooms."));
		}
		
		m_pGetPlayerNickname = (const char *(__thiscall *)(IClientFriends *, CSteamID)) FindSteamFunction("GetPlayerNickname");
		if(!m_pGetPlayerNickname)
		{
			wxGetApp().SetTrayIcon(CApp::k_EIconWarning, _("Nickname support is disabled"));
			wxGetApp().Warning(_("Unable to find GetPlayerNickname,\nNickname support is disabled."));
		}
	}

	return true;
}