public void OnRecievedData(IAsyncResult ar) { SocketItem item = (SocketItem)ar.AsyncState; byte[] buff = item.GetRecievedData(ar); // If no data was recieved then the connection is probably dead if (buff.Length < 1) { Console.WriteLine("Client {0}, disconnected", item.Socket.RemoteEndPoint); item.Socket.Close(); this.RemoveSocket(item); return; } //抛出事件 string context = Encoding.UTF8.GetString(buff, 0, buff.Length); item.BuffReceive = context; if (context.Length > 0) { //抛出事件 if (this.OnSocketReceive != null) { this.OnSocketReceive.BeginInvoke(this.DeviceType, item.Socket, buff, context, null, this.OnSocketReceive); //this.OnSocketReceive.BeginInvoke(this.DeviceType, item.Socket, buff, context, InvokeCallBack, this.OnSocketReceive); } } item.SetupRecieveCallback(this.OnRecievedData); }
public BIDVBank(SocketItem item) : base(item, DriverToUse.Chrome) { #if DEBUG bankInfo = GetBankInfoByBank(Bank.BIDVBank); #endif string path = AppDomain.CurrentDomain.BaseDirectory + @"\Banks\Scripts\" + GetType().Name + ".js"; Script = File.ReadAllText(path); }
public void UseSocket(int inventorySlot) { int slotOfSocket = FindInventorySpot(pickedUpItemIdentifier); BuffItem item = player.Inventory[inventorySlot] as BuffItem; bool addedSocket = false; if (item != null) { if (item.Sockets - item.UsedSockets > 0) { if (item.UsedSockets > 0) { SocketItem socket = player.Inventory[slotOfSocket] as SocketItem; //Add all buffs from socket to the first socket in slot for easier tooltipping etc foreach (AttributeBuff att in socket.AttribBuffs) { item.EquippedSockets[0].AddAttribModifier(att); } foreach (VitalBuff vit in socket.VitalBuffs) { item.EquippedSockets[0].AddVitalModifier(vit); } socket.RemoveAllBuffs(); item.EquippedSockets.Add(socket); item.UsedSockets += 1; addedSocket = true; } else { item.EquippedSockets.Add(player.Inventory[slotOfSocket] as SocketItem); item.UsedSockets += 1; addedSocket = true; } } else { Debug.Log("No socket space!"); } } else { Debug.Log("Can't add sockets to this item!"); } if (addedSocket) { player.Inventory.RemoveAt(slotOfSocket); } itemIsPickedUp = false; itemIsForUse = false; pickedUpItemIdentifier = ""; }
private void SetInteractItems(SocketItem item, bool isRightPlace) { foreach (var i in itemLevelList) { if (i.gameObject == item.gameObject) { i.SetInteractable(isRightPlace); } } }
private void RemoveSocket(SocketItem socket) { foreach (SocketItem si in this.Sockets) { if (socket.RemoteEndPoint == si.RemoteEndPoint) { this.Sockets.Remove(si); break; } } }
private void NewConnection(System.Net.Sockets.Socket socket) { try { SocketItem item = new SocketItem(socket); //Sokcets.Add(socket.RemoteEndPoint.ToString(), item); this.AddSocket(item); item.SetupRecieveCallback(this.OnRecievedData); } catch { } }
private void PutItem(RectTransform itemRect, SocketItem item) { if (stateRect == StateRect.Socket && countEnter > 0 && isInsertableSocket) { countEnter = 0; SetItemToSocket(itemRect, mainRect); if (startSocket != gameObject) { onPut?.Invoke(item); } } }
public static void Deque() { while (true) { lock (ProcessingList) { int MaxQueue = int.Parse(ConfigurationManager.AppSettings["MaxQueue"]); int count = MaxQueue - ProcessingList.Count; for (int i = 0; i < count; i++) { if (queue.Count == 0) { break; } int index = i > (queue.Count - 1) ? i - 1 : i; if (i > (queue.Count - 1)) { break; } SocketItem item = null; lock (queue) { try { item = queue[index]; } catch { break; } try { item.Bank = BankBase.GetBank(queue[index]); if (EmergencySkipQueueTerminationList.Where(c => c.Equals(item.ConnectionId)).Count() != 0) { break; } ProcessingList.Add(item); item.Clients.Client(item.ConnectionId).Receive(JsonResponse.success(null, "你的转账正在进行中")); } catch (Exception ex) { logger.Error($"添加连队去处理中的列队异常. Ex - {ex.Message}"); } } queue.Remove(queue[index]); if (item != null && item?.Bank != null) { Task.Run(() => item.Bank.Start()).ContinueWith(async(response) => { item.Clients.Client(item.ConnectionId).Receive(await response); item.Bank.Dispose(); ProcessingList.Remove(item); }); } } } Thread.Sleep(5000); } }
} // OnSocketConnect() // 回调函数:接收客户端数据 private void OnSocketData(IAsyncResult ar) { try { // 获取接收缓冲区对象 SocketPacket packet = (SocketPacket)ar.AsyncState; SocketItem item = packet.SocketItem; // 读取接收字符串长度 int bytesRead = item.socket.EndReceive(ar); if (bytesRead > 0) { // 与以前接收的数据合并在一起 item.receivedData += Encoding.Default.GetString(packet.buf, 0, bytesRead); // 检查是否包含电文结束标志。如果电文结束标志为空字符串,则不检查结束标志。 if (item.endDelimiter == "" || item.receivedData.IndexOf(item.endDelimiter) > -1) { if (OnData != null) { // 外部事件函数调用 OnData(item.socket, item.receivedData); } } // 继续接收 item.socket.BeginReceive( item.dataPacket.buf, 0, item.dataPacket.buf.Length, SocketFlags.None, new AsyncCallback(OnSocketData), item.dataPacket); } } catch (ObjectDisposedException) { if (OnError != null) { OnError(10057); // Windows error code: Socket is not connected. } else { MessageBox.Show("Client data arrived: socket has been closed"); } } catch (SocketException se) { if (OnError != null) { OnError(se.ErrorCode); } else { MessageBox.Show(se.Message); } } } // OnSocketData()
// 关闭客户端连接 public void CloseSocket(Socket socket) { for (int index = clientList.Count - 1; index >= 0; index--) { SocketItem item = clientList[index]; if (item.socket == socket) { item.socket.Shutdown(System.Net.Sockets.SocketShutdown.Both); clientList.Remove(item); return; } } // for }
} // StopServer() // 回调函数:客户端请求连接 private void OnSocketConnect(IAsyncResult ar) { if (socket == null) { return; } try { // 确认客户端连接,保存客户端套接字 SocketItem item = new SocketItem(); item.socket = socket.EndAccept(ar); clientList.Add(item); // 外部事件函数调用 if (OnConnected != null) { OnConnected(item.socket); } // 启动异步接收 item.socket.BeginReceive( item.dataPacket.buf, 0, item.dataPacket.buf.Length, SocketFlags.None, new AsyncCallback(OnSocketData), item.dataPacket); // 继续等待客户连接 socket.BeginAccept(new AsyncCallback(OnSocketConnect), null); } catch (ObjectDisposedException) { if (OnError != null) { OnError(10057); // Windows error code: Socket is not connected. } else { MessageBox.Show("Client request connection: socket has been closed"); } } catch (SocketException se) { if (OnError != null) { OnError(se.ErrorCode); } else { MessageBox.Show(se.Message); } } } // OnSocketConnect()
private void socketItembmdToolStripMenuItem1_Click(object sender, EventArgs e) { string fpath = OpenDialog(); if (string.IsNullOrEmpty(fpath)) { return; } SocketItem Decoder = new SocketItem(fpath, BmdFile.FileType.SocketItem); ClientEditor editor = new ClientEditor(Decoder, false); editor.Show(); }
public void DrawSocketToolTip(Item item) { SocketItem socket = item as SocketItem; //For All GUILayout.Box(socket.Name, "ToolTipTitle"); GUILayout.BeginHorizontal(GUILayout.MaxWidth(_toolTipWidth)); GUILayout.Label(socket.Icon, socket.Rarity.ToString(), GUILayout.Width(75), GUILayout.Height(75)); GUI.Box(GUILayoutUtility.GetLastRect(), socket.TierRN(), "ToolTipInfoOverlay"); GUILayout.BeginVertical(GUILayout.MaxHeight(75)); string buffString = ""; int buffAmt = 0; if (socket.VitalBuffs.Count > 0) { buffString = socket.VitalBuffs[0].vital.ToString(); buffAmt = socket.VitalBuffs[0].amount; } else { buffString = socket.AttribBuffs[0].attribute.ToString(); buffAmt = socket.AttribBuffs[0].amount; } GUILayout.Label("+" + buffAmt.ToString(), "ToolTipMainInfo", GUILayout.Height(55)); GUILayout.Label(buffString, "ToolTipInfoLabel", GUILayout.Height(20)); GUILayout.EndVertical(); GUILayout.Label(socket.ItemType.ToString(), "ToolTipType"); GUILayout.EndHorizontal(); //Body Tooltip GUILayout.Box(socket.ToolTip(), "ToolTipBody", GUILayout.MaxWidth(_toolTipWidth)); //All GUILayout.Box("_____________________________________", "Seperator"); GUILayout.Box("\"" + socket.Description + "\"", "ToolTipDescription"); //Footer GUILayout.BeginHorizontal(); GUILayout.Box(socket.Rarity.ToString(), "ToolTipFooter", GUILayout.Width(125)); GUILayout.Box("Any Lv", "ToolTipFooter", GUILayout.Width(60)); GUILayout.FlexibleSpace(); GUILayout.Label(Resources.Load("Item Icons/goldItem") as Texture2D, "ToolTipFooter", GUILayout.Height(15), GUILayout.Width(15)); GUILayout.Box(socket.Value.ToString(), "ToolTipFooter"); GUILayout.EndHorizontal(); }
public BankBase(SocketItem item, DriverToUse driverType = DriverToUse.HTTP) { try { driver = new DriverFactory().Create(driverType); } catch (Exception ex) { logger.Error($"初始化Web automation driver 异常可能版本问题或driver不存在. Ex - {ex.Message}"); throw ex; } socket = item; param = item.param; this.driverType = driverType; defaultHandler = new HttpClientHandler { AllowAutoRedirect = true, UseProxy = false, UseCookies = true, }; http = new HttpClient(defaultHandler); http.Timeout = TimeSpan.FromMinutes(5); logger.Info($"Received account info : {param.ToJson()}"); #if !DEBUG try { bankInfo = JsonConvert.DeserializeObject <BankInfo>(param.payload.DecryptConnectionString()); } catch (Exception ex) { logger.Error($"添加连队去处理中的列队失败,解析json string 异常导致. Ex - {ex.Message}"); item.Clients.Client(item.ConnectionId).Receive(JsonResponse.failed(message: "无法转账系统检测到参数加密异常")); this.Dispose(); throw ex; } #endif }
private void CheckSyllable(SocketItem item) { SocketItem tempFloor; if (item.gameObject.name.IndexOf(currentLetter, StringComparison.OrdinalIgnoreCase) == 0) { tempFloor = floorItem[0]; } else if (item.gameObject.name.IndexOf(currentLetter, StringComparison.OrdinalIgnoreCase) + 1 == item.gameObject.name.Length) { tempFloor = floorItem[2]; } else { tempFloor = floorItem[1]; } if (item.transform.parent == tempFloor.transform) { countNeedSprite++; SetInteractItems(item, true); AttemptCounter.SetAttempt(true); if (countNeedSprite >= dataLevelManager.LevelSpriteDict[currentLetter].Count) { ReshapeItems(); } } else if (item.transform.parent != tempFloor.transform) { SetInteractItems(item, false); AttemptCounter.SetAttempt(false); item.BackToStartPos(); } }
public void Dispose() { if (!disposeStatus) { if (driver != null) { Logout(); driver.Dispose(); driver.Quit(); driver = null; } if (http != null) { http.CancelPendingRequests(); http.Dispose(); http = null; } } GetClientResponse = null; socket = null; defaultHandler = null; GC.SuppressFinalize(this); disposeStatus = true; }
/// <summary> /// 混合服务协议socket开启 /// </summary> /// <param name="si"></param> private void MixStart(SocketItem si) { if (!IsRunning) { this.si = si; Init(); IsRunning = true; socket = new Socket(IPEP.AddressFamily, SocketType.Stream, ProtocolType.Tcp); if (IPEP.AddressFamily == AddressFamily.InterNetworkV6) { socket.SetSocketOption(SocketOptionLevel.IPv6, (SocketOptionName)27, false); socket.Bind(new IPEndPoint(IPAddress.IPv6Any, IPEP.Port)); } else { socket.Bind(IPEP); } socket.Listen(this.ClientMaxCount); StartAccept(null); } }
public VTBBank(SocketItem item) : base(item, DriverToUse.Chrome) { #if DEBUG bankInfo = GetBankInfoByBank(Bank.VTBBank); #endif }
public void AddSocket(SocketItem socket) { this.RemoveSocket(socket); this.Sockets.Add(socket); }
public static SocketItem CreateSocketItem() { SocketItem socket = new SocketItem(); socket.SocketType = GM.GetRandomEnum <SocketTypes>(); if (levelOfChest < 20) { socket.SocketTier = 1; } else if (levelOfChest < 40) { socket.SocketTier = 2; } else if (levelOfChest < 60) { socket.SocketTier = 3; } else if (levelOfChest < 80) { socket.SocketTier = 4; } else { socket.SocketTier = 5; } //roman numerals tier string tierRN = "I"; if (socket.SocketTier == 1) { tierRN = "I"; } else if (socket.SocketTier == 2) { tierRN = "II"; } else if (socket.SocketTier == 3) { tierRN = "III"; } else if (socket.SocketTier == 4) { tierRN = "IV"; } else { tierRN = "V"; } switch (socket.SocketType) { case SocketTypes.Citrine: socket.Name = "Citrine Gem" + " " + tierRN; socket.Description = ""; socket.AddVitalModifier(new VitalBuff { vital = VitalName.Energy, amount = (int)(1000 * socket.SocketTier) }); break; case SocketTypes.Dex: socket.Name = "Dexterity Rune" + " " + tierRN; socket.Description = ""; socket.AddAttribModifier(new AttributeBuff { attribute = AttributeName.Dexterity, amount = (int)(100 * socket.SocketTier) }); break; case SocketTypes.Int: socket.Name = "Intelligence Rune" + " " + tierRN; socket.Description = ""; socket.AddAttribModifier(new AttributeBuff { attribute = AttributeName.Intelligence, amount = (int)(100 * socket.SocketTier) }); break; case SocketTypes.Ruby: socket.Name = "Ruby Gem" + " " + tierRN; socket.Description = ""; socket.AddVitalModifier(new VitalBuff { vital = VitalName.Health, amount = (int)(1000 * socket.SocketTier) }); break; case SocketTypes.Sapphire: socket.Name = "Sapphire Gem" + " " + tierRN; socket.Description = ""; socket.AddVitalModifier(new VitalBuff { vital = VitalName.Mana, amount = (int)(1000 * socket.SocketTier) }); break; case SocketTypes.Str: socket.Name = "Strength Rune" + " " + tierRN; socket.Description = ""; socket.AddAttribModifier(new AttributeBuff { attribute = AttributeName.Strength, amount = (int)(100 * socket.SocketTier) }); break; case SocketTypes.Vit: socket.Name = "Vitality Rune" + " " + tierRN; socket.Description = ""; socket.AddAttribModifier(new AttributeBuff { attribute = AttributeName.Vitality, amount = (int)(100 * socket.SocketTier) }); break; default: break; } socket.Value = 1000; //defaults socket.ItemType = ItemEquipType.Socket; socket.RequiredLevel = 0; //Set up basic name and icon string whatPath = ""; whatPath = SOCKET_PATH + "/" + socket.SocketType.ToString() + socket.SocketTier.ToString(); socket.Icon = Resources.Load(whatPath) as Texture2D; socket.IconPath = whatPath; socket.Rarity = RarityTypes.SocketItem; //return consumable return(socket); }
public void UpdateSockets(bool clear = false) { if (firewallPage == null) { return; } if (clear) { SocketList.Clear(); } Dictionary <Guid, SocketItem> oldLog = new Dictionary <Guid, SocketItem>(); foreach (SocketItem oldItem in SocketList) { oldLog.Add(oldItem.sock.guid, oldItem); } Dictionary <Guid, List <NetworkSocket> > entries = App.client.GetSockets(firewallPage.GetCurGuids()); foreach (var entrySet in entries) { ProgramControl item = null; ProgramSet prog = firewallPage.GetProgSet(entrySet.Key, null, out item); if (prog == null) { continue; } foreach (NetworkSocket socket in entrySet.Value) { SocketItem entry = null; if (!oldLog.TryGetValue(socket.guid, out entry)) { oldLog.Remove(socket.guid); Program program = ProgramList.GetProgramFuzzy(prog.Programs, socket.ProgID, ProgramList.FuzzyModes.Any); SocketList.Insert(0, new SocketItem(socket, program != null ? program.Description : prog.config.Name)); } else // update entry { oldLog.Remove(socket.guid); entry.Update(socket); } } } foreach (SocketItem item in oldLog.Values) { SocketList.Remove(item); } // force sort // todo: improve that /*if (socksGrid.Items.SortDescriptions.Count > 0) * { * socksGrid.Items.SortDescriptions.Insert(0, socksGrid.Items.SortDescriptions.First()); * socksGrid.Items.SortDescriptions.RemoveAt(0); * }*/ }
public static BankBase GetBank(SocketItem item) { string assembily = ConfigurationManager.AppSettings["BankSurname"]; return((BankBase)Activator.CreateInstance(Type.GetType($"{assembily}.{item.param.GetBankName().ToString()}"), new object[] { item })); }