00001
00002
00003
00004
00005
00006
00007
00008
00009 #import <Cocoa/Cocoa.h>
00010 #import "PacketTypes.h"
00011 #import "Universe.h"
00012 #import "UdpStats.h"
00013 #import "LLNotificationCenter.h"
00014 #import "PingStats.h"
00015 #import "Luky.h"
00016 #include <unistd.h>
00017
00018 #define COMM_UPDATES_PER_SECOND 5
00019 #define MAX_PORT_RETRY 10
00020
00021 #define COMM_UDP_DIAG NO
00022 #define COMM_MAX_PORT_RETRY 10
00023
00024 #define COMM_SHORTVERSION 11
00025
00026 #define COMM_OLDSHORTVERSION 10
00027
00028 @interface Communication : NSObject {
00029 int commMode;
00030 int commStatus;
00031 int commModeRequest;
00032 int shortVersion;
00033 bool receiveShort;
00034 int ghostSlot;
00035 FeatureList *fList;
00036 PingStats *pStats;
00037 Universe *universe;
00038 UdpStats *udpStats;
00039 LLNotificationCenter *notificationCenter;
00040
00041 }
00042 - (id)initWithUniverse:(Universe*)newUniverse baseUdpPort:(int)basePort;
00043
00044 - (void)subscribeToNotifications;
00045 - (void) run;
00046 - (void) run:(id)sender;
00047
00048 - (void) setMultiThreaded:(bool) multi;
00049 -(void) setPing:(bool) received withResponse:(int)response;
00050 -(FeatureList*) featureList;
00051 -(PingStats*) pingStats;
00052 -(UdpStats*)udpStats;
00053 -(int)ghostSlot;
00054 -(void)setGhostSlot:(int) slot;
00055 -(int)commStatus;
00056 -(void)setCommStatus:(int)status;
00057 -(int)commMode;
00058 -(void)setCommMode:(int)mode;
00059 -(int)commModeRequest;
00060 -(void)setCommModeRequest:(int)mode;
00061 -(int)shortVersion;
00062 -(void)setShortVersion:(int)ver;
00063 -(bool)receiveShort;
00064 -(void)setReceiveShort:(bool)rs;
00065 -(int) packetsReceived;
00066 -(void)increasePacketsReceived;
00067 -(void)decreasePacketsReceived;
00068
00069 - (void) sendShortPacketWithId:(char) type;
00070 - (void) sendShortPacketNoForceWithId:(char) type state:(char) state;
00071 - (void) sendShortPacketWithId:(char) type boolState:(bool) state;
00072 - (void) sendShortPacketWithId:(char) type state:(char) state;
00073 - (void) sendServerPacketWithBuffer:(char*)buffer length:(int) size;
00074
00075 - (void) resetForce;
00076 - (int) forceCheckFlags:(int) flag force:(int) force type:(char)type;
00077 - (int) forceCheckValue:(int) value force:(int) force type:(char) type;
00078 - (int) forceCheckTractFlag:(int) flag force:(int) force type:(char) type;
00079 - (void) checkForce;
00080
00081 -(void)cleanUp:(id)sender;
00082 -(void)readFromServer;
00083 -(void)readFromServer:(id)sender;
00084 -(void)periodicReadFromServer;
00085
00086 - (void) sendSpeedReq:(NSNumber *) speed;
00087 - (void) sendDockingReq:(NSNumber *) on;
00088 - (void) sendCloakReq:(NSNumber *) on;
00089 - (void) sendRefitReq:(NSNumber *) ship;
00090 - (void) sendDirReq:(NSNumber *) dir;
00091 - (void) sendPhaserReq:(NSNumber *) dir;
00092 - (void) sendTorpReq:(NSNumber *) dir;
00093 - (void) sendPlasmaReq:(NSNumber *) dir;
00094 - (void) sendShieldReq:(NSNumber *) on;
00095 - (void) sendBombReq:(NSNumber *) bomb;
00096 - (void) sendBeamReq:(NSNumber *) up;
00097 - (void) sendRepairReq:(NSNumber *) on;
00098 - (void) sendOrbitReq:(NSNumber *) orbit;
00099 - (void) sendQuitReq:(id)sender;
00100 - (void) sendCoupReq:(id)sender;
00101 - (void) sendByeReq:(id)sender;
00102 - (void) sendPractrReq:(id)sender;
00103 - (void) sendDetonateReq:(id)sender;
00104 - (void) sendPlaylockReq:(NSNumber *) player;
00105 - (void) sendPlanlockReq:(NSNumber *) planet;
00106 - (void) sendResetStatsReq:(NSNumber *) verify;
00107 - (void) sendWarReq:(NSNumber *) mask;
00108 - (void) sendTractorOnReq:(NSNumber *) player;
00109 - (void) sendTractorOffReq:(NSNumber *) player;
00110 - (void) sendRepressorOnReq:(NSNumber *) player;
00111 - (void) sendRepressorOffReq:(NSNumber *) player;
00112 - (void) sendTeamReq:(NSDictionary *)newTeam;
00113 - (void) sendDetMineReq:(NSNumber *) torpId;
00114 - (void) sendFeature:(NSDictionary *)newFeature;
00115 - (void) sendLoginReq:(NSDictionary *)login;
00116 - (void) sendPingReq:(NSNumber *)start;
00117 - (void) sendServerPingResponse:(NSNumber *) number;
00118 - (void) sendMessage:(NSDictionary *)mess;
00119 - (void) sendUpdatePacket:(NSNumber *) updates_per_second;
00120 - (void) sendThreshold:(NSNumber*) threshold;
00121 - (void) sendDetonateMyTorpsReq:(id)sender;
00122 - (void) sendOptionsPacket:(id)sender;
00123 - (int) sendPickSocketReq;
00124 - (int) sendPickSocketReq:(NSNumber*) startAtPort;
00125 - (void) sendUdpReq:(NSNumber*) req;
00126 - (void) sendShortReq:(NSNumber*) req;
00127 - (void) sendUdpVerify:(id)sender;
00128
00129 - (bool) callServer:(NSString *) hostName port:(int) port;
00130 - (bool) startCommunicationThread;
00131 - (bool) stopCommunicationThread;
00132
00133 - (bool) connectToServerUsingPort:(int) port;
00134 - (bool) connectToServerUsingPort:(int) port expectedHost:(NSString *) host;
00135 - (bool) connectToServerUsingNextPort;
00136 - (int) sendSocketVersionAndNumberReq:(int)port;
00137
00138 - (bool) openUdpConn;
00139 - (void) closeUdpConn;
00140
00141 @end