Crossfire JXClient, Trunk  R20561
OutputCountTracker.java
Go to the documentation of this file.
1 /*
2  * This file is part of JXClient, the Fullscreen Java Crossfire Client.
3  *
4  * JXClient is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * JXClient is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with JXClient; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17  *
18  * Copyright (C) 2005-2008 Yann Chachkoff.
19  * Copyright (C) 2006-2011 Andreas Kirschbaum.
20  */
21 
22 package com.realtime.crossfire.jxclient.main;
23 
30 import org.jetbrains.annotations.NotNull;
31 
37 public class OutputCountTracker {
38 
42  @NotNull
44 
48  @NotNull
49  private final CommandQueue commandQueue;
50 
54  @NotNull
56 
57  @Override
58  public void delinvReceived(final int tag) {
59  // ignore
60  }
61 
62  @Override
63  public void delitemReceived(@NotNull final int[] tags) {
64  // ignore
65  }
66 
67  @Override
68  public void addItemReceived(final int location, final int tag, final int flags, final int weight, final int faceNum, @NotNull final String name, @NotNull final String namePl, final int anim, final int animSpeed, final int nrof, final int type) {
69  // ignore
70  }
71 
72  @Override
73  public void playerReceived(final int tag, final int weight, final int faceNum, @NotNull final String name) {
74  commandQueue.sendNcom(true, 1, "output-count 1"); // to make message merging work reliably
75  }
76 
77  @Override
78  public void upditemReceived(final int flags, final int tag, final int valLocation, final int valFlags, final int valWeight, final int valFaceNum, @NotNull final String valName, @NotNull final String valNamePl, final int valAnim, final int valAnimSpeed, final int valNrof) {
79  // ignore
80  }
81 
82  };
83 
88  @NotNull
89  @SuppressWarnings("FieldCanBeLocal")
91 
92  @Override
93  public void start() {
94  server.removeCrossfireUpdateItemListener(crossfireUpdateItemListener);
95  }
96 
97  @Override
98  public void metaserver() {
99  server.removeCrossfireUpdateItemListener(crossfireUpdateItemListener);
100  }
101 
102  @Override
103  public void preConnecting(@NotNull final String serverInfo) {
104  // ignore
105  }
106 
107  @Override
108  public void connecting(@NotNull final String serverInfo) {
109  server.addCrossfireUpdateItemListener(crossfireUpdateItemListener);
110  }
111 
112  @Override
113  public void connecting(@NotNull final ClientSocketState clientSocketState) {
114  // ignore
115  }
116 
117  @Override
118  public void connected() {
119  // ignore
120  }
121 
122  @Override
123  public void connectFailed(@NotNull final String reason) {
124  // ignore
125  }
126 
127  };
128 
135  public OutputCountTracker(@NotNull final GuiStateManager guiStateManager, @NotNull final CrossfireServerConnection server, @NotNull final CommandQueue commandQueue) {
136  this.server = server;
137  this.commandQueue = commandQueue;
138  guiStateManager.addGuiStateListener(guiStateListener);
139  }
140 
141 }
void addCrossfireUpdateItemListener(@NotNull CrossfireUpdateItemListener crossfireUpdateItemListener)
Adds a listener to be notified about item changes.
Interface for listeners interested gui state changes.
void sendNcom(final boolean mustSend, @NotNull final String command)
Sends an "ncom" command to the server.
final CommandQueue commandQueue
The CommandQueue for sending commands.
void removeCrossfireUpdateItemListener(@NotNull CrossfireUpdateItemListener crossfireUpdateItemListener)
Removes a listener to be notified about item changes.
final GuiStateListener guiStateListener
The GuiStateListener for detecting established or dropped connections.
OutputCountTracker(@NotNull final GuiStateManager guiStateManager, @NotNull final CrossfireServerConnection server, @NotNull final CommandQueue commandQueue)
Creates a new instance.
final CrossfireUpdateItemListener crossfireUpdateItemListener
The CrossfireUpdateItemListener to receive item updates.
Adds encoding/decoding of crossfire protocol packets to a ServerConnection.
Maintains the pending (ncom) commands sent to the server.
Tracks received Crossfire messages and resets the "output-count" setting whenever a player logs in...
Connection progress states of the Crossfire server connection.
final CrossfireServerConnection server
The CrossfireServerConnection to track.