-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNetworkMatchMakingSTEAM.lua
More file actions
167 lines (143 loc) · 5.61 KB
/
NetworkMatchMakingSTEAM.lua
File metadata and controls
167 lines (143 loc) · 5.61 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
function NetworkMatchMakingSTEAM:search_lobby(friends_only)
if not self:_has_callback("search_lobby") then
return
end
self._search_friends_only = false
local friend_lobbies = {}
local num_updated_friends_lobbies = 0
local function empty()
end
local info = {
room_list = {},
attribute_list = {}
}
local public_done = false
local friends_wanted = true
local friends_done = false
local function refresh_public_lobbies()
if not self.browser then
return
end
local lobbies = self.browser:lobbies()
if lobbies then
for _, lobby in ipairs(lobbies) do
if self._difficulty_filter == 0 or self._difficulty_filter == tonumber(lobby:key_value("difficulty")) then
table.insert(info.room_list, {
owner_id = lobby:key_value("owner_id"),
owner_name = lobby:key_value("owner_name"),
room_id = lobby:id(),
custom_text = lobby:key_value("custom_text")
})
table.insert(info.attribute_list, {
numbers = self:_lobby_to_numbers(lobby)
})
end
end
end
if not public_done then
public_done = true
end
if not friends_wanted or friends_done then
self:_call_callback("search_lobby", info)
end
end
local function refresh_friends_lobby(lobby)
lobby:setup_callback(empty)
num_updated_friends_lobbies = num_updated_friends_lobbies + 1
if num_updated_friends_lobbies >= #friend_lobbies then
for _, friend_lobby in ipairs(friend_lobbies) do
local ikey = friend_lobby:key_value(self._BUILD_SEARCH_INTEREST_KEY)
if ikey ~= "value_missing" and ikey ~= "value_pending" then
table.insert(info.room_list, {
owner_id = friend_lobby:key_value("owner_id"),
owner_name = friend_lobby:key_value("owner_name"),
room_id = friend_lobby:id(),
custom_text = friend_lobby:key_value("custom_text")
})
table.insert(info.attribute_list, {
numbers = self:_lobby_to_numbers(friend_lobby)
})
end
end
if not friends_done then
friends_done = true
end
if public_done then
self:_call_callback("search_lobby", info)
end
end
end
local user_id_to_filter_out = Steam:userid()
if managers.criminals and managers.criminals:get_num_player_criminals() > 1 and managers.network and managers.network:session() and managers.network:session():all_peers() then
user_id_to_filter_out = managers.network:session():all_peers()[1]:user_id()
end
-- FRIENDS ONLY LOBBIES
if Steam:logged_on() and Steam:friends() then
for _, friend in ipairs(Steam:friends()) do
local friend_lobby = friend:lobby()
if friend_lobby and user_id_to_filter_out ~= friend_lobby:key_value("owner_id") then
local filtered = nil
local filter_in_camp = tostring(self._lobby_filters.state.value)
local filter_difficulty = tostring(self._difficulty_filter)
local filter_job = tostring(self._lobby_filters.job_id.value)
if filter_in_camp == "1" and filter_in_camp ~= friend_lobby:key_value("state") then
filtered = true
elseif filter_difficulty ~= "0" and filter_difficulty ~= friend_lobby:key_value("difficulty") then
filtered = true
elseif filter_job ~= "-1" and filter_job ~= friend_lobby:key_value("job_id") then
filtered = true
end
if not filtered then
table.insert(friend_lobbies, friend_lobby)
end
end
end
end
if #friend_lobbies == 0 then
friends_wanted = false
friends_done = true
if public_done then
self:_call_callback("search_lobby", info)
end
else
for _, lobby in ipairs(friend_lobbies) do
lobby:setup_callback(refresh_friends_lobby)
if lobby:key_value("state") == "value_pending" then
lobby:request_data()
else
refresh_friends_lobby(lobby)
end
end
end
-- PUBLIC LOBBIES
self.browser = LobbyBrowser(refresh_public_lobbies, empty)
self.browser:set_interest_keys({
"owner_id",
"owner_name",
"level",
"difficulty",
"permission",
"state",
"num_players",
"drop_in",
"min_level",
"kick_option",
"job_class_min",
"job_class_max",
self._BUILD_SEARCH_INTEREST_KEY
})
self.browser:set_distance_filter(self._distance_filter)
self.browser:set_lobby_filter(self._BUILD_SEARCH_INTEREST_KEY, "true", "equal")
self.browser:set_lobby_filter("owner_id", user_id_to_filter_out, "not_equal")
for _, data in pairs(self._lobby_filters) do
if data.value and data.value ~= -1 then
self.browser:set_lobby_filter(data.key, data.value, data.comparision_type)
end
end
self.browser:set_max_lobby_return_count(self._lobby_return_count)
if Global.game_settings.playing_lan then
self.browser:refresh_lan()
else
self.browser:refresh()
end
end