game: Fix crashes related to missions. Don't broadcast if not in the same instance.
This commit is contained in:
parent
3ec9f898fe
commit
1bdc71ced3
@ -19,4 +19,4 @@
|
|||||||
%% EGS database schema.
|
%% EGS database schema.
|
||||||
|
|
||||||
-record(ids, {type, id}).
|
-record(ids, {type, id}).
|
||||||
-record(users, {gid, pid, socket, auth, time, folder, charnumber, charname, lid, quest, maptype, mapnumber, mapentry, direction, coords}).
|
-record(users, {gid, pid, socket, auth, time, folder, charnumber, charname, lid, instanceid, quest, maptype, mapnumber, mapentry, direction, coords}).
|
||||||
|
@ -65,6 +65,18 @@ users_select_all() ->
|
|||||||
users_select_others(GID) ->
|
users_select_others(GID) ->
|
||||||
do(qlc:q([X || X <- mnesia:table(users), X#users.gid /= GID, X#users.charnumber /= undefined])).
|
do(qlc:q([X || X <- mnesia:table(users), X#users.gid /= GID, X#users.charnumber /= undefined])).
|
||||||
|
|
||||||
|
%% @doc Select all other users in the same area. Return a list of #users records.
|
||||||
|
|
||||||
|
users_select_others_in_area(Self) ->
|
||||||
|
do(qlc:q([X || X <- mnesia:table(users),
|
||||||
|
X#users.gid /= Self#users.gid,
|
||||||
|
X#users.charnumber /= undefined,
|
||||||
|
X#users.instanceid =:= Self#users.instanceid,
|
||||||
|
X#users.quest =:= Self#users.quest,
|
||||||
|
X#users.maptype =:= Self#users.maptype,
|
||||||
|
X#users.mapnumber =:= Self#users.mapnumber
|
||||||
|
])).
|
||||||
|
|
||||||
%% @doc Insert or update an user.
|
%% @doc Insert or update an user.
|
||||||
|
|
||||||
users_insert(User) ->
|
users_insert(User) ->
|
||||||
|
@ -217,7 +217,7 @@ counter_load(CSocket, GID, Quest, MapType, MapNumber, MapEntry) ->
|
|||||||
|
|
||||||
lobby_load(CSocket, GID, Quest, MapType, MapNumber, MapEntry) ->
|
lobby_load(CSocket, GID, Quest, MapType, MapNumber, MapEntry) ->
|
||||||
OldUser = egs_db:users_select(GID),
|
OldUser = egs_db:users_select(GID),
|
||||||
User = OldUser#users{quest=Quest, maptype=MapType, mapnumber=MapNumber, mapentry=MapEntry},
|
User = OldUser#users{instanceid=undefined, quest=Quest, maptype=MapType, mapnumber=MapNumber, mapentry=MapEntry},
|
||||||
egs_db:users_insert(User),
|
egs_db:users_insert(User),
|
||||||
[{status, 1}, {char, Char}, {options, Options}] = char_load(User#users.folder, User#users.charnumber),
|
[{status, 1}, {char, Char}, {options, Options}] = char_load(User#users.folder, User#users.charnumber),
|
||||||
[{name, AreaName}, {quest, QuestFile}, {zone, ZoneFile}, {entries, _}] = proplists:get_value([Quest, MapType, MapNumber], ?MAPS,
|
[{name, AreaName}, {quest, QuestFile}, {zone, ZoneFile}, {entries, _}] = proplists:get_value([Quest, MapType, MapNumber], ?MAPS,
|
||||||
@ -262,7 +262,7 @@ lobby_load(CSocket, GID, Quest, MapType, MapNumber, MapEntry) ->
|
|||||||
|
|
||||||
mission_load(CSocket, GID, Quest, MapType, MapNumber, MapEntry) ->
|
mission_load(CSocket, GID, Quest, MapType, MapNumber, MapEntry) ->
|
||||||
OldUser = egs_db:users_select(GID),
|
OldUser = egs_db:users_select(GID),
|
||||||
User = OldUser#users{quest=Quest, maptype=MapType, mapnumber=MapNumber, mapentry=MapEntry},
|
User = OldUser#users{instanceid=GID, quest=Quest, maptype=MapType, mapnumber=MapNumber, mapentry=MapEntry},
|
||||||
egs_db:users_insert(User),
|
egs_db:users_insert(User),
|
||||||
[{status, 1}, {char, Char}, {options, _}] = char_load(User#users.folder, User#users.charnumber),
|
[{status, 1}, {char, Char}, {options, _}] = char_load(User#users.folder, User#users.charnumber),
|
||||||
[{name, AreaName}, {quest, QuestFile}, {zone, ZoneFile}, {entries, _}] = proplists:get_value([Quest, MapType, MapNumber], ?MAPS),
|
[{name, AreaName}, {quest, QuestFile}, {zone, ZoneFile}, {entries, _}] = proplists:get_value([Quest, MapType, MapNumber], ?MAPS),
|
||||||
@ -472,7 +472,7 @@ broadcast(Command, GID, Packet)
|
|||||||
LID = Self#users.lid,
|
LID = Self#users.lid,
|
||||||
SafePacket = << A/binary, 16#00011300:32, GID:32/little-unsigned-integer, B/binary,
|
SafePacket = << A/binary, 16#00011300:32, GID:32/little-unsigned-integer, B/binary,
|
||||||
GID:32/little-unsigned-integer, LID:32/little-unsigned-integer, C/binary >>,
|
GID:32/little-unsigned-integer, LID:32/little-unsigned-integer, C/binary >>,
|
||||||
lists:foreach(fun(User) -> User#users.pid ! {psu_broadcast, SafePacket} end, egs_db:users_select_others(GID))
|
lists:foreach(fun(User) -> User#users.pid ! {psu_broadcast, SafePacket} end, egs_db:users_select_others_in_area(Self))
|
||||||
end.
|
end.
|
||||||
|
|
||||||
%% @doc Movement (non-broadcast) handler. Do nothing.
|
%% @doc Movement (non-broadcast) handler. Do nothing.
|
||||||
|
Loading…
Reference in New Issue
Block a user