void OnNotify(NotifyEventCode code, uint retCode, object param1, object param2) { if (code == NotifyEventCode.SyncItemList) { OnItemListSynchronized(retCode, param1, param2); } else { Debug.Log("OnNotify code=" + code); } }
private void CallNotifyHandler(NotifyEventCode code, uint errCode, object param1, object param2) { Log(string.Format("[VAAL] CallNotifyHandler() : NC={0}, EC={1}, SS={2}, P1={3}, P2={4}", code, errCode, m_socketState, param1 != null ? param1 : "(null)", param2 != null ? param2 : "(null)")); lock (m_lockSocket) { switch (m_socketState) { case SocketState.Ready: if (errCode == (uint)ErrCode.NetworkIoWrite || errCode == (uint)ErrCode.NetworkIoRead || errCode == (uint)ErrCode.NetworkTimeout) { m_socketState = SocketState.Relogin; Thread thread = new Thread(new ThreadStart(ConnectThread)); thread.IsBackground = true; thread.Start(); return; } else if (errCode == (uint)ErrCode.VaalSvrWrongServerId && m_serverId == 0 && m_retryLoginPacket != null) { m_serverId = m_proxyServer.ServerConfig.GetServerId(m_retryLoginPacket.m_userID); ServerInfo serverInfo = m_proxyServer.ServerConfig.GetValServerInfo(m_serverId); if (m_proxyServer.LastConnectedServerIp != serverInfo.m_ip || m_proxyServer.LastConnectedServerPort != serverInfo.m_port) { m_proxyServer.SetLastConnectedServerInfo(serverInfo.m_ip, serverInfo.m_port); } m_socketState = SocketState.Login; Thread thread = new Thread(new ThreadStart(ConnectThread)); thread.IsBackground = true; thread.Start(); return; } //else if (errCode == (uint)ErrCode.NetworkConnectionClosedByServer) //{ // // 비동기 소켓모드에서는 이 에러는 정상종료 처리해야 하지만, // // 동기모드에서는 reconnect를 한다. // CloseSocket(); // m_socketState = SocketState.Relogin; //Thread thread = new Thread(new ThreadStart(m_server.ConnectThread)); //thread.IsBackground = true; //thread.Start(); // return; //} else if (errCode == (uint)ErrCode.VaalSvrPacketTransNum) { return; } break; case SocketState.Connecting: if (errCode == (uint)ErrCode.VaalSvrPacketTransNum || errCode == (uint)ErrCode.NetworkTimeout) { return; } break; case SocketState.Login: m_socketState = SocketState.Ready; break; case SocketState.Relogin: if (errCode == (uint)ErrCode.VaalSvrPacketTransNum || errCode == (uint)ErrCode.NetworkTimeout) { return; } else if (errCode == (uint)ErrCode.Success) { if (code == NotifyEventCode.Login) { return; } else if (code == NotifyEventCode.Sync) { List<RetryPacket> packets = new List<RetryPacket>(); lock (m_retryPackets) { foreach (RetryPacket rp in m_retryPackets) { packets.Add(rp); } m_retryPackets.Clear(); } lock (m_sendingPackets) { m_sendingPackets.InsertRange(0, packets); } m_socketState = SocketState.Ready; m_eventSendPacket.Set(); return; } } else { if (code == NotifyEventCode.Login) { code = NotifyEventCode.DisconnectFromServer; } } break; case SocketState.Disconnected: break; } } if (code == NotifyEventCode.DisconnectFromServer) { List<RetryPacket> packets = new List<RetryPacket>(); lock (m_retryPackets) { foreach (RetryPacket rp in m_retryPackets) { packets.Add(rp); } m_retryPackets.Clear(); } foreach (RetryPacket rp in packets) { m_notifyHandler(rp.m_nec, errCode, param1, param2); } CleanupResource(); m_proxyServer.SetLoginState(false); } m_notifyHandler(code, errCode, param1, param2); }
public WorkToClient(ServerEventHandler handler, NotifyEventCode nec, uint retCode, object param1, object param2) { m_handler = handler; m_nec = nec; m_retCode = retCode; m_param1 = param1; m_param2 = param2; }
private void OnNotifyHandler(NotifyEventCode nec, uint errCode, object param1, object param2) { Log(string.Format("[PSVR] OnNotifyHandler() : NC={0}, EC={1}, P1={2}, P2={3}", nec, errCode, param1 != null ? param1 : "(null)", param2 != null ? param2 : "(null)")); bool isNotifyHandlerCalled = true; try { switch (nec) { case NotifyEventCode.DisconnectFromServer: //if (m_serverMakara != null) //{ // m_serverMakara.CloseConnection(); //} break; case NotifyEventCode.GetItemListHash: { if (errCode == (uint)ErrCode.Success) { ItemDataType itemType = (ItemDataType)(byte)param1; switch (itemType) { case ItemDataType.Stage: m_stageManager.SetHashFromServer((uint)param2); m_stageManager.GetStageList(); break; case ItemDataType.Item: m_itemManager.SetHashFromServer((uint)param2); m_itemManager.GetItemList(); break; } isNotifyHandlerCalled = false; } else { nec = NotifyEventCode.SyncItemList; } } break; case NotifyEventCode.GetItemList: { nec = NotifyEventCode.SyncItemList; if (errCode == (uint)ErrCode.Success) { ItemDataType itemType = (ItemDataType)(byte)param1; if (itemType == ItemDataType.Stage) { m_serverVal.GetItemListHash(ItemDataType.Item); isNotifyHandlerCalled = false; } } } break; } if (isNotifyHandlerCalled) { m_notifyHandler(nec, errCode, param1, param2); //Thread thread = new Thread(new ThreadStart(new WorkToClient(m_notifyHandler, nec, errCode, param1, param2).CallWork)); //thread.IsBackground = true; //thread.Start(); } } catch (Exception e) { Log(string.Format("[PSVR] OnNotifyHandler() : Error occurred : {0}", e.Message)); } }