private void SendBaseInfoTimer_Elapsed(object sender, ElapsedEventArgs e) { string methodMD5 = "B5BE9A7B29C08AD2"; try { log.Generate(methodMD5 + " 进入"); if (gameData.SendInfoSuccess) { lock (sendData) { sendData.Clear(); if (startPing == false) { lastPing = Environment.TickCount; startPing = true; CCSerializeTool.IntToByteList(lastPing, sendData); } else { CCSerializeTool.IntToByteList(Environment.TickCount, sendData); } client.SendPackage(1, sendData.ToArray()); } } else { lock (sendData) { sendData.Clear(); CCSerializeTool.IntToByteList(gameData.Line, sendData); sendData.AddRange(machineIdentity); CCSerializeTool.StringToByteList(CCProcessInfo.GetProcessPath(GetWuXiaProcess()), sendData); client.SendPackage(0, sendData.ToArray()); } } sendBaseInfoTimer.Start(); } catch (Exception exception) { log.Generate(methodMD5 + " 异常,异常信息:" + exception.Message); log.Flush(); throw; } finally { log.Generate(methodMD5 + " 退出"); } }
private void Client_OnReceivePackageEvent(int signal, byte[] buffer) { string methodMD5 = "3C8905B3EE89BB1A"; try { log.Generate(methodMD5 + " 进入"); int startIndex = 0; int ping; switch (signal) { case 0: gameData.SendInfoSuccess = true; int licence = CCSerializeTool.ByteToInt(buffer, ref startIndex); if (!gameData.Licence.Contains(licence)) { gameData.Licence.Add(licence); } gameData.No1Qin = CCSerializeTool.ByteToString(buffer, ref startIndex); gameData.No2Qin = CCSerializeTool.ByteToString(buffer, ref startIndex); gameData.No3Qin = CCSerializeTool.ByteToString(buffer, ref startIndex); gameData.No4Qin = CCSerializeTool.ByteToString(buffer, ref startIndex); for (int i = 0; i < 12; i++) { gameData.QinKey[i] = CCSerializeTool.ByteToInt(buffer, ref startIndex); } gameData.QinKey = gameData.QinKey; for (int i = 0; i < gameData.HitQinKey.Length; i++) { gameData.HitQinKey[i] = buffer[startIndex++]; } gameData.HitQinKey = gameData.HitQinKey; pingTimer.Start(); break; case 1: ping = Environment.TickCount - CCSerializeTool.ByteToInt(buffer, ref startIndex); startPing = false; gameData.Ping = ping > 9999 ? 9999 : (ping < 0 ? 9999 : ping); break; case 2: for (int i = 0; i < gameData.HitQinKey.Length; i++) { gameData.HitQinKey[i] = buffer[startIndex++]; } gameData.HitQinKey = gameData.HitQinKey; break; case 3: gameData.Licence.Clear(); gameData.Licence.Add(CCSerializeTool.ByteToInt(buffer, ref startIndex)); gameData.No1Qin = gameData.No2Qin = gameData.No3Qin = gameData.No4Qin = ""; for (int i = 0; i < gameData.QinKey.Count; i++) { gameData.QinKey[i] = 0; } gameData.QinKey = gameData.QinKey; for (int i = 0; i < gameData.HitQinKey.Length; i++) { gameData.HitQinKey[i] = 0; } gameData.HitQinKey = gameData.HitQinKey; gameData.HitKeyIndex = 0; break; case 4: ping = Environment.TickCount - CCSerializeTool.ByteToInt(buffer, ref startIndex); startPing = false; gameData.Ping = ping > 9999 ? 9999 : (ping < 0 ? 9999 : ping); lock (sendData) { sendData.Clear(); sendData.AddRange(machineIdentity); CCSerializeTool.StringToByteList(CCProcessInfo.GetProcessPath(GetWuXiaProcess()), sendData); client.SendPackage(8, sendData.ToArray()); } break; case 5: gameData.No1Qin = CCSerializeTool.ByteToString(buffer, ref startIndex); break; case 6: gameData.No2Qin = CCSerializeTool.ByteToString(buffer, ref startIndex); break; case 7: gameData.No3Qin = CCSerializeTool.ByteToString(buffer, ref startIndex); break; case 8: gameData.No4Qin = CCSerializeTool.ByteToString(buffer, ref startIndex); break; case 9: for (int i = 0; i < 12; i++) { gameData.QinKey[i] = CCSerializeTool.ByteToInt(buffer, ref startIndex); } gameData.QinKey = gameData.QinKey; break; case 10: for (int i = 0; i < 12; i++) { gameData.QinKey[i] = CCSerializeTool.ByteToInt(buffer, ref startIndex); } gameData.QinKey = gameData.QinKey; int keyIndex = CCSerializeTool.ByteToInt(buffer, ref startIndex); if (!gameData.Licence.Contains(gameData.QinKey[keyIndex])) { SystemSounds.Asterisk.Play(); Dispatcher.Invoke(() => { Storyboard Storyboard1 = FindResource("Storyboard1") as Storyboard; Storyboard1.Stop(); Storyboard.SetTargetName(Storyboard1, "OneKey" + keyIndex.ToString()); Storyboard1.Begin(); }); } break; default: break; } } catch (Exception exception) { log.Generate(methodMD5 + " 异常,异常信息:" + exception.Message); log.Flush(); throw; } finally { log.Generate(methodMD5 + " 退出"); } }