summaryrefslogtreecommitdiff
path: root/protocols/Steam/src/steam_instances.cpp
blob: edd1eaef7f649b0eae4fa9bf4a209f2445f214e2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include "stdafx.h"

int CSteamProto::CompareProtos(const CSteamProto *p1, const CSteamProto *p2)
{
	return lstrcmp(p1->m_tszUserName, p2->m_tszUserName);
}

LIST<CSteamProto> CSteamProto::InstanceList(1, CSteamProto::CompareProtos);

CSteamProto* CSteamProto::InitProtoInstance(const char* protoName, const wchar_t* userName)
{
	CSteamProto *ppro = new CSteamProto(protoName, userName);
	InstanceList.insert(ppro);

	return ppro;
}

int CSteamProto::UninitProtoInstance(CSteamProto* ppro)
{
	InstanceList.remove(ppro);
	delete ppro;

	return 0;
}

void CSteamProto::UninitProtoInstances()
{
	for (int i = InstanceList.getCount(); i > 0; i--)
		UninitProtoInstance(InstanceList[i]);
	InstanceList.destroy();
}

CSteamProto* CSteamProto::GetContactProtoInstance(MCONTACT hContact)
{
	char *proto = (char *)::CallService(MS_PROTO_GETCONTACTBASEPROTO, hContact, 0);

	if (proto == NULL)
		return NULL;

	for (int i = 0; i < InstanceList.getCount(); i++)
		if (!mir_strcmp(proto, InstanceList[i]->m_szModuleName))
			return InstanceList[i];

	return NULL;
}