mirror of
https://github.com/2006-Scape/apollo.git
synced 2026-07-06 00:38:18 +00:00
Housekeeping
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
<?xml version="1.0"?>
|
||||
<plugin>
|
||||
<id>chat-privacy</id>
|
||||
<version>1</version>
|
||||
<name>Chat privacy</name>
|
||||
<description>Adds chat privacy support.</description>
|
||||
<authors>
|
||||
<author>Major</author>
|
||||
</authors>
|
||||
<scripts>
|
||||
<script>privacy.rb</script>
|
||||
</scripts>
|
||||
<dependencies>
|
||||
<dependency>private-messaging</dependency>
|
||||
</dependencies>
|
||||
</plugin>
|
||||
@@ -0,0 +1,12 @@
|
||||
require 'java'
|
||||
|
||||
java_import 'org.apollo.game.model.entity.setting.PrivacyState'
|
||||
java_import 'org.apollo.game.message.impl.SendFriendMessage'
|
||||
|
||||
on :message, :privacy_option do |player, message|
|
||||
player.chat_privacy = message.chat_privacy
|
||||
player.friend_privacy = message.friend_privacy
|
||||
player.trade_privacy = message.trade_privacy
|
||||
|
||||
update_friends(player, message.friend_privacy == PrivacyState::OFF ? 0 : player.world_id)
|
||||
end
|
||||
@@ -0,0 +1,102 @@
|
||||
require 'java'
|
||||
|
||||
java_import 'org.apollo.game.message.impl.FriendServerStatusMessage'
|
||||
java_import 'org.apollo.game.message.impl.IgnoreListMessage'
|
||||
java_import 'org.apollo.game.message.impl.SendFriendMessage'
|
||||
java_import 'org.apollo.game.model.World'
|
||||
java_import 'org.apollo.game.model.entity.setting.ServerStatus'
|
||||
java_import 'org.apollo.game.model.entity.setting.PrivacyState'
|
||||
java_import 'org.apollo.game.model.entity.Player'
|
||||
|
||||
# Processes an add friend message, updating the logged-in status of the player (and the person they
|
||||
# added) if necessary.
|
||||
on :message, :add_friend do |player, message|
|
||||
friend_username = message.username
|
||||
player_username = player.username
|
||||
|
||||
player.add_friend(friend_username)
|
||||
friend = $world.get_player(friend_username)
|
||||
|
||||
if friend.nil? # the friend the player added is offline
|
||||
player.send(SendFriendMessage.new(friend_username, 0))
|
||||
elsif friend.friends_with(player_username)
|
||||
|
||||
# player's private chat state is not off, so notify the friend
|
||||
unless player.friend_privacy == PrivacyState::OFF
|
||||
friend.send(SendFriendMessage.new(player_username, player.world_id))
|
||||
end
|
||||
|
||||
# new friend's private chat state is not off, so notify the player
|
||||
unless friend.friend_privacy == PrivacyState::OFF
|
||||
player.send(SendFriendMessage.new(friend_username, friend.world_id))
|
||||
end
|
||||
elsif friend.friend_privacy == PrivacyState::ON
|
||||
# new friend doesn't have the player added but their private chat state is on, so inform the
|
||||
# player of the world they are on.
|
||||
player.send(SendFriendMessage.new(friend_username, friend.world_id))
|
||||
end
|
||||
end
|
||||
|
||||
# Processes a remove friend message, updating the logged-in status of the player if necessary.
|
||||
on :message, :remove_friend do |player, message|
|
||||
friend_username = message.username
|
||||
player_username = player.username
|
||||
|
||||
player.remove_friend(friend_username)
|
||||
if $world.is_player_online(friend_username)
|
||||
friend = $world.get_player(friend_username)
|
||||
|
||||
remove = friend.friends_with(player_username) && player.friend_privacy != PrivacyState::ON
|
||||
friend.send(SendFriendMessage.new(player_username, 0)) if remove
|
||||
end
|
||||
end
|
||||
|
||||
# Update the friend server status and send the friend/ignore lists of the player logging in.
|
||||
on :login do |_event, player|
|
||||
player.send(FriendServerStatusMessage.new(ServerStatus::CONNECTING))
|
||||
player.send(IgnoreListMessage.new(player.ignored_usernames)) if player.ignored_usernames.size > 0
|
||||
|
||||
username = player.username
|
||||
world = $world
|
||||
iterator = player.friend_usernames.iterator
|
||||
|
||||
# Iterate the player's friend list and notify the player that they are online if they are
|
||||
while iterator.has_next
|
||||
friend_username = iterator.next
|
||||
friend = world.get_player(friend_username)
|
||||
friend_world_id = (friend.nil? || !viewable?(friend, username)) ? 0 : friend.world_id
|
||||
|
||||
player.send(SendFriendMessage.new(friend_username, friend_world_id))
|
||||
end
|
||||
|
||||
player.send(FriendServerStatusMessage.new(ServerStatus::ONLINE))
|
||||
update_friends(player, player.world_id)
|
||||
end
|
||||
|
||||
# Notifies the player's friends that the player has logged out.
|
||||
on :logout do |_event, player|
|
||||
update_friends(player, 0)
|
||||
end
|
||||
|
||||
# Notifies the currently logged in players that the specified player has logged into the specified
|
||||
# world, unless the newly logged-in player has their friend privacy state set to 'off'.
|
||||
def update_friends(player, world = 0)
|
||||
privacy = player.friend_privacy
|
||||
|
||||
iterator = $world.player_repository.iterator
|
||||
username = player.username
|
||||
|
||||
while iterator.has_next
|
||||
other = iterator.next
|
||||
next if !other.friends_with(username) || other == player
|
||||
|
||||
world = viewable?(player, other.username) ? world : 0
|
||||
other.send(SendFriendMessage.new(username, world))
|
||||
end
|
||||
end
|
||||
|
||||
# Checks if the specified player can be viewed by the player with the specified other username
|
||||
def viewable?(player, other_username)
|
||||
privacy = player.friend_privacy
|
||||
privacy != PrivacyState::OFF && player.friends_with(other_username) || privacy == PrivacyState::ON
|
||||
end
|
||||
@@ -0,0 +1,9 @@
|
||||
on :message, :add_ignore do |player, message|
|
||||
username = message.username
|
||||
player.add_ignore(username)
|
||||
end
|
||||
|
||||
on :message, :remove_ignore do |player, message|
|
||||
username = message.username
|
||||
player.remove_ignore(username)
|
||||
end
|
||||
@@ -0,0 +1,23 @@
|
||||
require 'java'
|
||||
|
||||
java_import 'org.apollo.game.message.impl.ForwardPrivateChatMessage'
|
||||
java_import 'org.apollo.game.model.World'
|
||||
java_import 'org.apollo.game.model.entity.setting.PrivacyState'
|
||||
|
||||
on :message, :private_chat do |player, message|
|
||||
friend = $world.get_player(message.username)
|
||||
|
||||
if interaction_permitted(player, friend)
|
||||
chat = message.compressed_chat
|
||||
friend.send(ForwardPrivateChatMessage.new(player.username, player.privilege_level, chat))
|
||||
end
|
||||
end
|
||||
|
||||
# Checks if the sender is permitted to interact with the friend they have added:
|
||||
def interaction_permitted(sender, friend)
|
||||
username = sender.username
|
||||
return false if friend.nil? || friend.has_ignored(username)
|
||||
|
||||
privacy = friend.friend_privacy
|
||||
friend.friends_with(username) ? (privacy != PrivacyState::OFF) : (privacy == PrivacyState::ON)
|
||||
end
|
||||
@@ -0,0 +1,16 @@
|
||||
<?xml version="1.0"?>
|
||||
<plugin>
|
||||
<id>private-messaging</id>
|
||||
<version>1</version>
|
||||
<name>Private Messaging</name>
|
||||
<description>Adds friend and ignore list support, and private messaging.</description>
|
||||
<authors>
|
||||
<author>Major</author>
|
||||
</authors>
|
||||
<scripts>
|
||||
<script>friend.rb</script>
|
||||
<script>ignore.rb</script>
|
||||
<script>messaging.rb</script>
|
||||
</scripts>
|
||||
<dependencies />
|
||||
</plugin>
|
||||
Reference in New Issue
Block a user