正在查看: RummyCircle v11000.89 应用的 GameTableSocketAdapter.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
正在查看: RummyCircle v11000.89 应用的 GameTableSocketAdapter.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
package com.games24x7.dynamicrc.unitymodule.util.sockets.gametablesocket;
import com.games24x7.coregame.common.utility.crashlytics.CrashlyticsUtility;
import com.games24x7.coregame.common.utility.log.Logger;
import com.games24x7.coregame.common.utility.runtimevars.RunTimeVarsUtility;
import com.games24x7.coregame.rnmodule.util.ConnectionStatusReceiver;
import com.games24x7.dynamicrc.unitymodule.util.logger.LoggerConstants;
import com.games24x7.dynamicrc.unitymodule.util.logger.LoggerUtility;
import com.google.android.exoplayer2.video.spherical.c;
import com.neovisionaries.ws.client.H;
import com.neovisionaries.ws.client.I;
import com.neovisionaries.ws.client.L;
import com.neovisionaries.ws.client.M;
import com.neovisionaries.ws.client.Q;
import com.neovisionaries.ws.client.WebSocketException;
import java.net.Socket;
import java.net.URI;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import kotlin.Metadata;
import kotlin.Unit;
import kotlin.jvm.internal.Intrinsics;
import kotlin.text.StringsKt;
import org.jetbrains.annotations.NotNull;
import org.json.JSONException;
import org.json.JSONObject;
@Metadata
public final class GameTableSocketAdapter extends I {
private long AAID;
private int GT_WS_CONNECTION_TIMEOUT;
private int HEART_BEAT_RESPONSE;
private int HEART_BEAT_TIMER;
private int MAX_PONG_INTERVAL;
@NotNull
private final String TAG;
@NotNull
private final GameTableListener handlerInterface;
private boolean heartbeatOnAnyMessage;
private boolean isUserInitiated;
@NotNull
private JSONObject mDataObject;
private long mPlayerId;
private boolean mShowPn;
private H mWebSocket;
private int pingCount;
private int pingTimerID;
private int pongTimerID;
private L socketFactory;
public GameTableSocketAdapter(@NotNull GameTableListener gameTableListener, @NotNull String str, long j) {
Intrinsics.checkNotNullParameter(gameTableListener, "handlerInterface");
Intrinsics.checkNotNullParameter(str, "hostUrl");
this.handlerInterface = gameTableListener;
this.TAG = "GameTableSocketAdapter";
RunTimeVarsUtility runTimeVarsUtility = RunTimeVarsUtility.INSTANCE;
this.MAX_PONG_INTERVAL = RunTimeVarsUtility.getIntRunTimeVar$default(runTimeVarsUtility, "max_pong_interval", 0, 2, (Object) null);
this.GT_WS_CONNECTION_TIMEOUT = 5000;
this.HEART_BEAT_TIMER = RunTimeVarsUtility.getIntRunTimeVar$default(runTimeVarsUtility, "heart_beat_timer", 0, 2, (Object) null);
this.HEART_BEAT_RESPONSE = 2097154;
this.mDataObject = new JSONObject();
this.pongTimerID = -1;
this.pingTimerID = -1;
this.AAID = j;
this.heartbeatOnAnyMessage = runTimeVarsUtility.getBooleanRunTimeVar("heartbeatOnAnyMessage", false);
}
public final void addLogsIntoLogger(String str) {
LoggerUtility.INSTANCE.addLogs(String.valueOf(this.AAID), str);
}
private final boolean isConnected() {
boolean z;
H h = this.mWebSocket;
if (h != null) {
if ((h != null ? h.j() : null) != Q.e) {
z = true;
Logger.d$default(Logger.INSTANCE, this.TAG, "isConnected :: State is :: " + z, false, 4, (Object) null);
return z;
}
}
z = false;
Logger.d$default(Logger.INSTANCE, this.TAG, "isConnected :: State is :: " + z, false, 4, (Object) null);
return z;
}
private final void resetPingTimer() {
synchronized (this) {
GameTableSocketTimerInterface.INSTANCE.clearPGTimeout(this.pingTimerID);
this.pingTimerID = -1;
Unit unit = Unit.a;
}
}
private final void resetPongTimer() {
synchronized (this) {
GameTableSocketTimerInterface.INSTANCE.clearPGTimeout(this.pongTimerID);
this.pongTimerID = -1;
Unit unit = Unit.a;
}
}
private final void sendDisconnectToUnity() {
synchronized (this) {
try {
if (this.mWebSocket != null) {
stopHeartBeat();
H h = this.mWebSocket;
if (h != null) {
c cVar = h.e;
synchronized (((List) cVar.c)) {
try {
if (((List) cVar.c).remove(this)) {
cVar.a = true;
}
} finally {
}
}
}
this.mWebSocket = null;
if (!this.isUserInitiated) {
GameTableListener gameTableListener = this.handlerInterface;
JSONObject jSONObject = new JSONObject();
jSONObject.put("action", "OnSocketDisconnected");
jSONObject.put("aaid", this.AAID);
gameTableListener.onResponse(jSONObject);
}
}
Unit unit = Unit.a;
} catch (Throwable th) {
throw th;
}
}
}
private final void startHeartbeatTimer() {
Logger.d$default(Logger.INSTANCE, this.TAG, "startHeartbeatTimer :: Starting HeartBeat timer :: aaid = " + this.AAID, false, 4, (Object) null);
synchronized (this) {
if (this.pingTimerID < 0 || this.pongTimerID < 0) {
this.pingTimerID = GameTableSocketTimerInterface.INSTANCE.setPGTimeout(this.HEART_BEAT_TIMER, new GamerTableSocketTimerTask() {
@Override
public void run() {
int i;
super.run();
GameTableSocketAdapter gameTableSocketAdapter = GameTableSocketAdapter.this;
synchronized (this) {
try {
i = gameTableSocketAdapter.pingTimerID;
if (i >= 0) {
gameTableSocketAdapter.pingTimerID = -1;
gameTableSocketAdapter.sendHeartBeatMessage();
}
Unit unit = Unit.a;
} catch (Throwable th) {
throw th;
}
}
}
});
Unit unit = Unit.a;
}
}
}
private final void startPongTimer() {
Logger.d$default(Logger.INSTANCE, "HeartBeatData", "Starting ping timer " + this.AAID, false, 4, (Object) null);
synchronized (this) {
this.pongTimerID = GameTableSocketTimerInterface.INSTANCE.setPGTimeout(this.MAX_PONG_INTERVAL, new GamerTableSocketTimerTask() {
@Override
public void run() {
int i;
long j;
GameTableListener gameTableListener;
long j2;
H h;
long j3;
Socket socket;
super.run();
GameTableSocketAdapter gameTableSocketAdapter = GameTableSocketAdapter.this;
synchronized (this) {
try {
i = gameTableSocketAdapter.pongTimerID;
if (i >= 0) {
gameTableSocketAdapter.pongTimerID = -1;
Logger logger = Logger.INSTANCE;
j = gameTableSocketAdapter.AAID;
Logger.d$default(logger, "HeartBeatData", "Pong not received " + j, false, 4, (Object) null);
gameTableListener = gameTableSocketAdapter.handlerInterface;
JSONObject jSONObject = new JSONObject();
jSONObject.put("action", "OnGTHeartBeatFailed");
j2 = gameTableSocketAdapter.AAID;
jSONObject.put("aaid", j2);
gameTableListener.onResponse(jSONObject);
h = gameTableSocketAdapter.mWebSocket;
Integer valueOf = (h == null || (socket = h.b.i) == null) ? null : Integer.valueOf(socket.hashCode());
j3 = gameTableSocketAdapter.AAID;
gameTableSocketAdapter.addLogsIntoLogger("WEBSOCKET :: " + valueOf + " :: HBFailed :: aaid = " + j3 + " :: isInternetConnected :: " + ConnectionStatusReceiver.INSTANCE.isConnected());
gameTableSocketAdapter.disconnect(false);
}
Unit unit = Unit.a;
} catch (Throwable th) {
throw th;
}
}
}
});
Unit unit = Unit.a;
}
}
public final void changeTournamentId(long j) {
Logger.d$default(Logger.INSTANCE, "HeartBeatData", "change Tournament Id " + j, false, 4, (Object) null);
try {
JSONObject jSONObject = this.mDataObject.getJSONObject("value");
Intrinsics.checkNotNullExpressionValue(jSONObject, "mDataObject.getJSONObject(\"value\")");
jSONObject.put("tournamentid", j);
this.mDataObject.put("value", jSONObject);
} catch (JSONException e) {
e.printStackTrace();
}
}
public final void disconnect(boolean z) {
Socket socket;
Socket socket2;
Logger.d$default(Logger.INSTANCE, this.TAG, "disconnect :: Socket Disconnect called :: Initiated by User " + z + " :: aaid => " + this.AAID, false, 4, (Object) null);
synchronized (this) {
try {
this.isUserInitiated = z;
stopHeartBeat();
if (isConnected()) {
try {
H h = this.mWebSocket;
if (h != null && (socket = h.b.i) != null) {
r3 = Integer.valueOf(socket.hashCode());
}
addLogsIntoLogger("WEBSOCKET :: " + r3 + " :: disconnect :: aaid = " + this.AAID + " :: isInternetConnected :: " + ConnectionStatusReceiver.INSTANCE.isConnected());
H h2 = this.mWebSocket;
if (h2 != null) {
h2.h();
}
} catch (Exception e) {
Logger logger = Logger.INSTANCE;
String str = this.TAG;
e.printStackTrace();
Logger.e$default(logger, str, "disconnect :: Got Exception :: " + Unit.a, false, 4, (Object) null);
CrashlyticsUtility.logException$default(CrashlyticsUtility.INSTANCE, e, (String) null, (HashMap) null, 6, (Object) null);
}
} else {
H h3 = this.mWebSocket;
if (h3 != null && (socket2 = h3.b.i) != null) {
r3 = socket2 != null ? Integer.valueOf(socket2.hashCode()) : null;
addLogsIntoLogger("WEBSOCKET :: " + r3 + " :: onDisconnected :: aaid = " + this.AAID + " :: isInternetConnected :: " + ConnectionStatusReceiver.INSTANCE.isConnected());
}
}
sendDisconnectToUnity();
Unit unit = Unit.a;
} catch (Throwable th) {
throw th;
}
}
}
public final boolean getHeartbeatOnAnyMessage() {
return this.heartbeatOnAnyMessage;
}
public final void initiateConnection(@NotNull String str) {
Intrinsics.checkNotNullParameter(str, "strHost");
Logger.i$default(Logger.INSTANCE, this.TAG, "initiateConnection :: Socket Initiation started :: Host Url = " + str + " and aaid = " + this.AAID, false, 4, (Object) null);
if (isConnected()) {
return;
}
try {
if (this.socketFactory == null) {
L l = new L();
int i = this.GT_WS_CONNECTION_TIMEOUT;
if (i < 0) {
throw new IllegalArgumentException("timeout value cannot be negative.");
}
l.c = i;
this.socketFactory = l;
}
L l2 = this.socketFactory;
if (l2 != null) {
l2.d = new String[]{new URI(str).getHost()};
}
L l3 = this.socketFactory;
Intrinsics.c(l3);
H a = l3.a(l3.c, str);
a.c(this);
a.a();
a.g();
this.mWebSocket = a;
} catch (Exception e) {
Logger logger = Logger.INSTANCE;
String str2 = this.TAG;
e.printStackTrace();
Logger.e$default(logger, str2, "initiateConnection :: Got Exception :: Error " + Unit.a, false, 4, (Object) null);
}
}
public void onConnectError(@NotNull H h, @NotNull WebSocketException webSocketException) {
Socket socket;
Socket socket2;
Intrinsics.checkNotNullParameter(h, "websocket");
Intrinsics.checkNotNullParameter(webSocketException, "exception");
super.onConnectError(h, webSocketException);
Logger logger = Logger.INSTANCE;
String str = this.TAG;
H h2 = this.mWebSocket;
Integer valueOf = (h2 == null || (socket2 = h2.b.i) == null) ? null : Integer.valueOf(socket2.hashCode());
Logger.e$default(logger, str, "onConnectError :: HasCode is :: " + valueOf + " :: aaid = " + this.AAID, false, 4, (Object) null);
H h3 = this.mWebSocket;
int hashCode = (h3 == null || (socket = h3.b.i) == null) ? 999 : socket.hashCode();
addLogsIntoLogger("WEBSOCKET :: " + hashCode + " :: onConnectError :: aaid = " + this.AAID + " :: isInternetConnected :: " + ConnectionStatusReceiver.INSTANCE.isConnected());
if (this.mWebSocket != null) {
disconnect(false);
}
}
public void onConnected(@NotNull H h, @NotNull Map<String, ? extends List<String>> map) throws Exception {
Socket socket;
Socket socket2;
Intrinsics.checkNotNullParameter(h, "websocket");
Intrinsics.checkNotNullParameter(map, "headers");
Logger logger = Logger.INSTANCE;
String str = this.TAG;
long j = this.AAID;
H h2 = this.mWebSocket;
Integer num = null;
Logger.i$default(logger, str, "onConnected :: Socket connected :: AAID " + j + " :: HasCode is :: " + ((h2 == null || (socket2 = h2.b.i) == null) ? null : Integer.valueOf(socket2.hashCode())), false, 4, (Object) null);
H h3 = this.mWebSocket;
if (h3 != null && (socket = h3.b.i) != null) {
num = Integer.valueOf(socket.hashCode());
}
addLogsIntoLogger("WEBSOCKET :: " + num + " :: OnConnected :: aaid = " + this.AAID);
GameTableListener gameTableListener = this.handlerInterface;
JSONObject jSONObject = new JSONObject();
jSONObject.put("action", "OnSocketOpen");
jSONObject.put("aaid", this.AAID);
gameTableListener.onResponse(jSONObject);
}
public void onDisconnected(@NotNull H h, @NotNull M m, @NotNull M m2, boolean z) throws Exception {
Intrinsics.checkNotNullParameter(h, "websocket");
Intrinsics.checkNotNullParameter(m, "serverCloseFrame");
Intrinsics.checkNotNullParameter(m2, "clientCloseFrame");
if (this.mWebSocket != null) {
addLogsIntoLogger("WEBSOCKET :: " + h.b.i.hashCode() + " :: onDisconnected :: aaid = " + this.AAID + " :: isInternetConnected :: " + ConnectionStatusReceiver.INSTANCE.isConnected());
sendDisconnectToUnity();
}
}
public void onError(H h, @NotNull WebSocketException webSocketException) {
Socket socket;
Intrinsics.checkNotNullParameter(webSocketException, "cause");
Logger logger = Logger.INSTANCE;
Logger.e$default(logger, this.TAG, "::onSuperError:: Exception is :: " + webSocketException, false, 4, (Object) null);
if (this.mWebSocket != null) {
Logger.e$default(logger, this.TAG, "onError :: Disconnecting socket", false, 4, (Object) null);
disconnect(false);
}
H h2 = this.mWebSocket;
int hashCode = (h2 == null || (socket = h2.b.i) == null) ? 999 : socket.hashCode();
addLogsIntoLogger("WEBSOCKET :: " + hashCode + " :: onError :: aaid = " + this.AAID + " :: isInternetConnected :: " + ConnectionStatusReceiver.INSTANCE.isConnected());
}
public void onTextMessage(@NotNull H h, @NotNull String str) {
Intrinsics.checkNotNullParameter(h, "websocket");
Intrinsics.checkNotNullParameter(str, "message");
Logger logger = Logger.INSTANCE;
Logger.d$default(logger, this.TAG, "onTextMessage :: Received message is :: " + str + " :: aaid is " + this.AAID, false, 4, (Object) null);
try {
if (this.heartbeatOnAnyMessage) {
synchronized (this) {
try {
if (this.pongTimerID >= 0) {
resetPongTimer();
startHeartbeatTimer();
}
Unit unit = Unit.a;
} finally {
}
}
}
if (StringsKt.E(str, "heartbeat", false)) {
JSONObject jSONObject = new JSONObject(str).getJSONObject("value");
if (jSONObject.isNull("classID") || jSONObject.getInt("classID") != this.HEART_BEAT_RESPONSE) {
return;
}
Logger.d$default(logger, this.TAG, "onTextMessage :: Pong Received...", false, 4, (Object) null);
if (this.heartbeatOnAnyMessage) {
return;
}
synchronized (this) {
try {
if (this.pongTimerID >= 0) {
resetPongTimer();
startHeartbeatTimer();
}
Unit unit2 = Unit.a;
} finally {
}
}
return;
}
JSONObject jSONObject2 = new JSONObject();
jSONObject2.put("data", str);
String jSONObject3 = jSONObject2.toString();
Intrinsics.checkNotNullExpressionValue(jSONObject3, "JSONObject().apply {\n … }.toString()");
GameTableListener gameTableListener = this.handlerInterface;
JSONObject jSONObject4 = new JSONObject();
jSONObject4.put("action", "onServerMessageReceivedFromNativeGT");
jSONObject4.put("aaid", this.AAID);
jSONObject4.put("mplayerid", this.mPlayerId);
jSONObject4.put("showPn", this.mShowPn);
jSONObject4.put("data", jSONObject3);
gameTableListener.onResponse(jSONObject4);
H h2 = this.mWebSocket;
if (h2 != null) {
Socket socket = h2.b.i;
Integer valueOf = socket != null ? Integer.valueOf(socket.hashCode()) : null;
addLogsIntoLogger("WEBSOCKET :: " + valueOf + " :: Received :: " + jSONObject3 + " :: aaid = " + this.AAID + " :: isInternetConnected :: " + ConnectionStatusReceiver.INSTANCE.isConnected());
}
} catch (Exception e) {
Logger logger2 = Logger.INSTANCE;
String str2 = this.TAG;
e.printStackTrace();
Logger.e$default(logger2, str2, "onTextMessage :: Got Exception :: " + Unit.a, false, 4, (Object) null);
CrashlyticsUtility.logException$default(CrashlyticsUtility.INSTANCE, e, (String) null, (HashMap) null, 6, (Object) null);
}
}
public final void sendHeartBeat(@NotNull String str) {
Intrinsics.checkNotNullParameter(str, "socketData");
try {
this.mDataObject = new JSONObject(str);
startHeartbeatTimer();
} catch (JSONException e) {
Logger logger = Logger.INSTANCE;
String str2 = this.TAG;
e.printStackTrace();
Logger.e$default(logger, str2, "sendHeartBeat :: Got Exception :: " + Unit.a, false, 4, (Object) null);
CrashlyticsUtility.logException$default(CrashlyticsUtility.INSTANCE, e, (String) null, (HashMap) null, 6, (Object) null);
}
}
public final void sendHeartBeatMessage() {
try {
JSONObject jSONObject = this.mDataObject;
int i = this.pingCount;
this.pingCount = i + 1;
jSONObject.put(LoggerConstants.METADATA_LOG_ID, i);
this.mDataObject.put("st", System.currentTimeMillis());
this.mDataObject.put("systime", System.currentTimeMillis());
Logger.d$default(Logger.INSTANCE, "HeartBeatData", "Pinging " + this.mDataObject + " tableId = " + this.AAID, false, 4, (Object) null);
sendMessage(this.mDataObject.toString() + "\r");
startPongTimer();
} catch (JSONException e) {
e.printStackTrace();
}
}
public final void sendMessage(@NotNull String str) {
Socket socket;
Intrinsics.checkNotNullParameter(str, "message");
Logger logger = Logger.INSTANCE;
Logger.e$default(logger, this.TAG, "sendMessage :: Input Message is :: " + str, false, 4, (Object) null);
try {
if (isConnected()) {
H h = this.mWebSocket;
if (h != null) {
h.n(str);
}
if (StringsKt.E(str, "heartbeat", false)) {
return;
}
Logger.e$default(logger, this.TAG, "sendMessage :: " + str + " is send to the server :: aaid is " + this.AAID, false, 4, (Object) null);
H h2 = this.mWebSocket;
Integer valueOf = (h2 == null || (socket = h2.b.i) == null) ? null : Integer.valueOf(socket.hashCode());
addLogsIntoLogger("WEBSOCKET :: " + valueOf + " :: Sent :: message = " + str + " and aaid = " + this.AAID);
}
} catch (Exception e) {
Logger logger2 = Logger.INSTANCE;
String str2 = this.TAG;
e.printStackTrace();
Logger.e$default(logger2, str2, "sendMessage :: Got Exception :: " + Unit.a, false, 4, (Object) null);
}
}
public final void setHeartbeatOnAnyMessage(boolean z) {
this.heartbeatOnAnyMessage = z;
}
public final void stopHeartBeat() {
Logger.d$default(Logger.INSTANCE, this.TAG, "stopHeartBeat :: Stopping HeartBeat for table " + this.AAID, false, 4, (Object) null);
this.pingCount = 0;
resetPongTimer();
resetPingTimer();
}
public final void updateMplayerId(long j) {
Logger.d$default(Logger.INSTANCE, "updateMplayerId", "change mPlayer Id " + j, false, 4, (Object) null);
this.mPlayerId = j;
}
public final void updateShowPn(boolean z) {
Logger.e$default(Logger.INSTANCE, this.TAG, "updateShowPn :: Status is " + z, false, 4, (Object) null);
this.mShowPn = z;
}
}