00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "CClientProxy1_4.h"
00020 #include "CProtocolUtil.h"
00021 #include "CLog.h"
00022 #include "IEventQueue.h"
00023 #include "TMethodEventJob.h"
00024 #include <cstring>
00025 #include <memory>
00026 #include "CServer.h"
00027 #include "CCryptoStream.h"
00028
00029
00030
00031
00032
00033 CClientProxy1_4::CClientProxy1_4(const CString& name, synergy::IStream* stream, CServer* server, IEventQueue* eventQueue) :
00034 CClientProxy1_3(name, stream, eventQueue), m_server(server)
00035 {
00036 assert(m_server != NULL);
00037 }
00038
00039 CClientProxy1_4::~CClientProxy1_4()
00040 {
00041 }
00042
00043 void
00044 CClientProxy1_4::gameDeviceButtons(GameDeviceID id, GameDeviceButton buttons)
00045 {
00046 LOG((CLOG_DEBUG2 "send game device buttons to \"%s\" id=%d buttons=%d", getName().c_str(), id, buttons));
00047 CProtocolUtil::writef(getStream(), kMsgDGameButtons, id, buttons);
00048 }
00049
00050 void
00051 CClientProxy1_4::gameDeviceSticks(GameDeviceID id, SInt16 x1, SInt16 y1, SInt16 x2, SInt16 y2)
00052 {
00053 LOG((CLOG_DEBUG2 "send game device sticks to \"%s\" id=%d s1=%+d,%+d s2=%+d,%+d", getName().c_str(), id, x1, y1, x2, y2));
00054 CProtocolUtil::writef(getStream(), kMsgDGameSticks, id, x1, y1, x2, y2);
00055 }
00056
00057 void
00058 CClientProxy1_4::gameDeviceTriggers(GameDeviceID id, UInt8 t1, UInt8 t2)
00059 {
00060 LOG((CLOG_DEBUG2 "send game device triggers to \"%s\" id=%d t1=%d t2=%d", getName().c_str(), id, t1, t2));
00061 CProtocolUtil::writef(getStream(), kMsgDGameTriggers, id, t1, t2);
00062 }
00063
00064 void
00065 CClientProxy1_4::gameDeviceTimingReq()
00066 {
00067 LOG((CLOG_DEBUG2 "send game device timing request to \"%s\"", getName().c_str()));
00068 CProtocolUtil::writef(getStream(), kMsgCGameTimingReq);
00069 }
00070
00071 void
00072 CClientProxy1_4::keyDown(KeyID key, KeyModifierMask mask, KeyButton button)
00073 {
00074 cryptoIv();
00075 CClientProxy1_3::keyDown(key, mask, button);
00076 }
00077
00078 void
00079 CClientProxy1_4::keyRepeat(KeyID key, KeyModifierMask mask, SInt32 count, KeyButton button)
00080 {
00081 cryptoIv();
00082 CClientProxy1_3::keyRepeat(key, mask, count, button);
00083 }
00084
00085 void
00086 CClientProxy1_4::keyUp(KeyID key, KeyModifierMask mask, KeyButton button)
00087 {
00088 cryptoIv();
00089 CClientProxy1_3::keyUp(key, mask, button);
00090 }
00091
00092 void
00093 CClientProxy1_4::cryptoIv()
00094 {
00095 CCryptoStream* cryptoStream = dynamic_cast<CCryptoStream*>(getStream());
00096 if (cryptoStream == NULL) {
00097 return;
00098 }
00099
00100 byte iv[CRYPTO_IV_SIZE];
00101 cryptoStream->newIv(iv);
00102 CString data(reinterpret_cast<const char*>(iv), CRYPTO_IV_SIZE);
00103
00104 LOG((CLOG_DEBUG2 "send crypto iv change to \"%s\"", getName().c_str()));
00105 CProtocolUtil::writef(getStream(), kMsgDCryptoIv, &data);
00106
00107
00108
00109 cryptoStream->setEncryptIv(iv);
00110 }
00111
00112 bool
00113 CClientProxy1_4::parseMessage(const UInt8* code)
00114 {
00115
00116 if (memcmp(code, kMsgCGameTimingResp, 4) == 0) {
00117 gameDeviceTimingResp();
00118 }
00119
00120 else if (memcmp(code, kMsgDGameFeedback, 4) == 0) {
00121 gameDeviceFeedback();
00122 }
00123
00124 else {
00125 return CClientProxy1_3::parseMessage(code);
00126 }
00127
00128 return true;
00129 }
00130
00131 void
00132 CClientProxy1_4::gameDeviceFeedback()
00133 {
00134
00135 GameDeviceID id;
00136 UInt16 m1, m2;
00137 CProtocolUtil::readf(getStream(), kMsgDGameFeedback + 4, &id, &m1, &m2);
00138 LOG((CLOG_DEBUG2 "recv game device feedback id=%d m1=%d m2=%d", id, m1, m2));
00139
00140
00141 m_server->gameDeviceFeedback(id, m1, m2);
00142 }
00143
00144 void
00145 CClientProxy1_4::gameDeviceTimingResp()
00146 {
00147
00148 UInt16 freq;
00149 CProtocolUtil::readf(getStream(), kMsgCGameTimingResp + 4, &freq);
00150 LOG((CLOG_DEBUG2 "recv game device timing response freq=%dms", freq));
00151
00152
00153 m_server->gameDeviceTimingResp(freq);
00154 }