Пример #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 HSteamPipe CreateSteamPipe() override
	{
		return m_baseEngine->CreateSteamPipe();
	}