RuneHive-Game
Loading...
Searching...
No Matches
com.runehive.net.session.GameSession Class Reference

Represents a Session when a Player has been authenticated and active in the game world. More...

Inheritance diagram for com.runehive.net.session.GameSession:
Collaboration diagram for com.runehive.net.session.GameSession:

Public Member Functions

Player getPlayer ()
void handleClientPacket (Object o)
 The method that is called when the client sends packets to the server.
void processClientPackets ()
void processServerPacketQueue ()
void queueServerPacket (GamePacket packet)
Public Member Functions inherited from com.runehive.net.session.Session
final void close ()
 The method to close this session.
Channel getChannel ()
 Gets the underlying Channel for this Session.
String getHost ()
 Gets the users host address.
 Session (Channel channel)
 Creates a new Session.

Protected Member Functions

void onClose (ChannelFuture f)
 The method called after a session has been closed.

Package Functions

 GameSession (Channel channel, Player player)

Private Member Functions

void queueClientPacket (final GamePacket packet)

Private Attributes

final MessagePassingQueue< GamePacketincomingPackets = new MpscArrayQueue<>(Config.CLIENT_PACKET_THRESHOLD)
final MessagePassingQueue< GamePacketoutgoingPackets = new MpscArrayQueue<>(Config.SERVER_PACKET_THRESHOLD)
final Player player

Static Private Attributes

static final Logger logger = LogManager.getLogger(GameSession.class)

Additional Inherited Members

Protected Attributes inherited from com.runehive.net.session.Session
final Channel channel
 The channel attached to this session.
final String host
 The users host address.

Detailed Description

Represents a Session when a Player has been authenticated and active in the game world.

Author
nshusa

Definition at line 21 of file GameSession.java.

Constructor & Destructor Documentation

◆ GameSession()

com.runehive.net.session.GameSession.GameSession ( Channel channel,
Player player )
package

Definition at line 33 of file GameSession.java.

33 {
34 super(channel);
35 this.player = player;
36 }

References com.runehive.net.session.Session.channel, and player.

Member Function Documentation

◆ getPlayer()

Player com.runehive.net.session.GameSession.getPlayer ( )

Definition at line 103 of file GameSession.java.

103 {
104 return player;
105 }

References player.

◆ handleClientPacket()

void com.runehive.net.session.GameSession.handleClientPacket ( Object o)

The method that is called when the client sends packets to the server.

Parameters
oThe vague object packet.

Reimplemented from com.runehive.net.session.Session.

Definition at line 39 of file GameSession.java.

39 {
40 if (o instanceof GamePacket) {
41 queueClientPacket((GamePacket) o);
42 }
43 }

References queueClientPacket().

Here is the call graph for this function:

◆ onClose()

void com.runehive.net.session.GameSession.onClose ( ChannelFuture future)
protected

The method called after a session has been closed.

Parameters
futureThe result of the session being closed.

Reimplemented from com.runehive.net.session.Session.

Definition at line 46 of file GameSession.java.

46 {
47 World.queueLogout(player);
48 }

References player, and com.runehive.game.world.World.queueLogout().

Here is the call graph for this function:

◆ processClientPackets()

void com.runehive.net.session.GameSession.processClientPackets ( )

Definition at line 54 of file GameSession.java.

54 {
55 final MessagePassingQueue<GamePacket> incomingPackets = this.incomingPackets;
56 final Player player = this.player;
57
58 for (int i = 0; i < Config.CLIENT_PACKET_THRESHOLD; i++) {
59 final GamePacket packet = incomingPackets.poll();
60 if (packet == null) break;
61
62 try {
63 PacketRepository.sendToListener(player, packet);
64 } catch (Exception ex) {
65 logger.error(String.format("error processing client packet for %s", player), ex);
66 } finally {
67 packet.release();
68 }
69 }
70 }

References com.runehive.Config.CLIENT_PACKET_THRESHOLD, incomingPackets, logger, player, and com.runehive.net.packet.PacketRepository.sendToListener().

Referenced by com.runehive.game.engine.sync.task.PlayerPreUpdateTask.run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ processServerPacketQueue()

void com.runehive.net.session.GameSession.processServerPacketQueue ( )

Definition at line 76 of file GameSession.java.

76 {
77 final Channel channel = this.channel;
78 final boolean channelActive = channel.isActive();
79
80 final MessagePassingQueue<GamePacket> outgoingPackets = this.outgoingPackets;
81
82 int count = 0;
83 for (; count < Config.SERVER_PACKET_THRESHOLD; count++) {
84 final GamePacket packet = outgoingPackets.poll();
85 if (packet == null) break;
86 if (channelActive) {
87 try {
88 channel.write(packet, channel.voidPromise());
89 } catch (final Exception ex) {
90 logger.error(String.format("error writing packet %s for %s", packet, player));
91 }
92 } else {
93 if (packet.refCnt() > 0) {
94 packet.release();
95 }
96 }
97 }
98 if (channelActive && count > 0) {
99 channel.flush();
100 }
101 }

References com.runehive.net.session.Session.channel, logger, outgoingPackets, player, and com.runehive.Config.SERVER_PACKET_THRESHOLD.

Referenced by com.runehive.game.engine.sync.task.PlayerPostUpdateTask.run().

Here is the caller graph for this function:

◆ queueClientPacket()

void com.runehive.net.session.GameSession.queueClientPacket ( final GamePacket packet)
private

Definition at line 50 of file GameSession.java.

50 {
51 incomingPackets.offer(packet);
52 }

References incomingPackets.

Referenced by handleClientPacket().

Here is the caller graph for this function:

◆ queueServerPacket()

void com.runehive.net.session.GameSession.queueServerPacket ( GamePacket packet)

Definition at line 72 of file GameSession.java.

72 {
73 outgoingPackets.offer(packet);
74 }

References outgoingPackets.

Member Data Documentation

◆ incomingPackets

final MessagePassingQueue<GamePacket> com.runehive.net.session.GameSession.incomingPackets = new MpscArrayQueue<>(Config.CLIENT_PACKET_THRESHOLD)
private

Definition at line 27 of file GameSession.java.

Referenced by processClientPackets(), and queueClientPacket().

◆ logger

final Logger com.runehive.net.session.GameSession.logger = LogManager.getLogger(GameSession.class)
staticprivate

Definition at line 23 of file GameSession.java.

Referenced by processClientPackets(), and processServerPacketQueue().

◆ outgoingPackets

final MessagePassingQueue<GamePacket> com.runehive.net.session.GameSession.outgoingPackets = new MpscArrayQueue<>(Config.SERVER_PACKET_THRESHOLD)
private

Definition at line 30 of file GameSession.java.

Referenced by processServerPacketQueue(), and queueServerPacket().

◆ player

final Player com.runehive.net.session.GameSession.player
private

The documentation for this class was generated from the following file: