private static async void SendDeviceToCloudMessagesAsync(MsgBody msgObj) { var messageString = JsonConvert.SerializeObject(msgObj); var message = new Message(Encoding.ASCII.GetBytes(messageString)); await deviceClient.SendEventAsync(message); }
public void hSockTcpKilllogReq(sbyte killerType, int killer, sbyte victimType, int victim, int weaponBy, int slot, int category, int hitpart, Dictionary <int, int> damageLog) { MsgBody msgBody = new MsgBody(); int id = UnityEngine.Random.Range(0, int.MaxValue); msgBody.Write(id); msgBody.Write(killerType); msgBody.Write(killer); msgBody.Write(victimType); msgBody.Write(victim); msgBody.Write(weaponBy); msgBody.Write(slot); msgBody.Write(category); msgBody.Write(hitpart); if (damageLog == null) { msgBody.Write(0); } else { msgBody.Write(damageLog.Count); foreach (KeyValuePair <int, int> item in damageLog) { msgBody.Write(item.Key); msgBody.Write(item.Value); } } ClientExtension.instance.lastKillLogMsg = msgBody; ClientExtension.instance.lastKillLogId = id; CSNetManager.Instance.Sock.Say(44, msgBody); }
public Msg4Send(ushort id, uint meta, uint src, MsgBody msgBody, byte sendKey) { uint offset = (uint)msgBody.Offset; byte b = 0; if (sendKey == 255) { for (int i = 0; i < offset; i++) { b = (byte)(b ^ msgBody.Buffer[i]); } } else { for (int j = 0; j < offset; j++) { b = (byte)(b ^ msgBody.Buffer[j]); msgBody.Buffer[j] ^= sendKey; } } _io = 0; _buffer = new byte[15 + offset]; MsgHdr msgHdr = new MsgHdr(offset, id, b, meta, src); byte[] array = msgHdr.ToArray(); Array.Copy(array, _buffer, array.Length); Array.Copy(msgBody.Buffer, 0L, _buffer, array.Length, offset); }
private void hSockTcpHandleShooterToolListAck(MsgBody msg) { msg.Read(out int count); for (int i = 0; i < count; i++) { msg.Read(out sbyte slot); msg.Read(out long seq); ClientExtension.instance.inventory.AddToolSlot(seq, slot); if (MyInfoManager.Instance.ShooterTools.Length > slot) { if (seq < 0) { MyInfoManager.Instance.ShooterTools[slot] = -1L; } else { Item itemBySequence = MyInfoManager.Instance.GetItemBySequence(seq); if (itemBySequence != null && itemBySequence.Template != null && itemBySequence.Template.type == TItem.TYPE.SPECIAL) { MyInfoManager.Instance.ShooterTools[slot] = seq; } } } } }
private static async void SendDeviceToCloudMessagesAsync(MsgBody tmpMsg) { var message = new Message(Encoding.ASCII.GetBytes(JsonConvert.SerializeObject(tmpMsg))); await deviceClient.SendEventAsync(message); Console.WriteLine("{0} > Sending message: {1}", DateTime.Now, JsonConvert.SerializeObject(tmpMsg)); }
private void hSockTcpHandleWeaponSlotListAck(MsgBody msg) { msg.Read(out int count); for (int i = 0; i < count; i++) { msg.Read(out int slot); msg.Read(out long seq); ClientExtension.instance.inventory.AddWeaponSlot(seq, (sbyte)slot); if (MyInfoManager.Instance.WeaponSlots.Length > slot) { if (seq < 0) { MyInfoManager.Instance.WeaponSlots[slot] = -1L; } else { Item itemBySequence = MyInfoManager.Instance.GetItemBySequence(seq); if (itemBySequence != null && itemBySequence.Template != null && itemBySequence.Template.type == TItem.TYPE.WEAPON) { MyInfoManager.Instance.WeaponSlots[slot] = seq; } } } } }
private void hSockTcpRendezvousInfoAck(MsgBody msg) { msg.Read(out int _); msg.Read(out string val2); msg.Read(out int val3); P2PManager.Instance.Bootup(val2, val3); P2PManager.Instance.rendezvousPointed = true; }
public void setMsgBody(MsgBody msg) { this.ID = msg.ID; this.Ip = msg.Ip; this.Status = msg.Status; this.TS = msg.TS; this.Change = msg.Change; }
public MsgReference(ushort _id, MsgBody _msg, ClientReference _client, SendType _sendType = SendType.Unicast) { msg = new Msg2Handle(_id, _msg); sendType = _sendType; if (_client != null) { client = _client; } }
private void hSockTcpKilllogAck(MsgBody msg) { msg.Read(out int id); if (id == ClientExtension.instance.lastKillLogId) { ClientExtension.instance.lastKillLogId = -1; } SockTcpKilllogAckHook.CallOriginal(CSNetManager.Instance.Sock, new object[] { msg }); }
private void hSockTcpEnterAck(MsgBody msg) { msg.Read(out int slot); msg.Read(out int seq); msg.Read(out string val2); msg.Read(out string val3); msg.Read(out int val4); msg.Read(out string val5); msg.Read(out int val6); msg.Read(out int val7); string[] array = new string[val7]; for (int j = 0; j < val7; j++) { msg.Read(out array[j]); } msg.Read(out int val8); msg.Read(out int val9); msg.Read(out int val10); msg.Read(out string val11); msg.Read(out int val12); msg.Read(out int val13); msg.Read(out byte val14); msg.Read(out val7); string[] array2 = (val7 > 0) ? new string[val7] : null; for (int j = 0; j < val7; j++) { msg.Read(out array2[j]); } msg.Read(out val7); string[] array3 = (val7 > 0) ? new string[val7] : null; for (int k = 0; k < val7; k++) { msg.Read(out array3[k]); } BrickManManager.Instance.OnEnter(seq, val2, array, val8, val9, val10, val11, val12, val13, array2, array3); BrickManManager.Instance.GetDesc(seq).Slot = (sbyte)slot; if (seq != MyInfoManager.Instance.Seq) { P2PManager.Instance.Add(seq, val3, val4, val5, val6, val14); if (RoomManager.Instance.CurrentRoom >= 0) { GameObject gameObject = GameObject.Find("Main"); if (null != gameObject) { gameObject.BroadcastMessage("OnChat", new ChatText(ChatText.CHAT_TYPE.SYSTEM, seq, val2, StringMgr.Instance.Get("ENTERED"))); } } } else { MyInfoManager.Instance.Slot = (sbyte)slot; } }
public MsgBody Flush() { MsgBody result = new MsgBody(_buffer, 15, (int)_hdr._size); _io -= (int)(15 + _hdr._size); if (_io > 0) { Array.Copy(_buffer, 15 + _hdr._size, _buffer, 0L, _io); } return(result); }
private void HandleConnected(MsgBody msg) { clientConnected = true; MainGUI.instance.setupHidden = true; GameObject gameObject = GameObject.Find("Main"); if (null != gameObject) { gameObject.BroadcastMessage("OnSeed"); } }
private void HandleReceiveSlotData(MsgBody msg) { msg.Read(out int count); for (int i = 0; i < count; i++) { msg.Read(out int slot); msg.Read(out int seq); msg.Read(out string name); msg.Read(out string ip); msg.Read(out int port); msg.Read(out string remoteIp); msg.Read(out int remotePort); msg.Read(out int equipCount); string[] equipment = new string[equipCount]; for (int j = 0; j < equipCount; j++) { msg.Read(out equipment[j]); } msg.Read(out int status); msg.Read(out int xp); msg.Read(out int clanSeq); msg.Read(out string clanName); msg.Read(out int clanMark); msg.Read(out int rank); msg.Read(out byte playerflag); msg.Read(out equipCount); string[] wpnChg = (equipCount > 0) ? new string[equipCount] : null; for (int j = 0; j < equipCount; j++) { msg.Read(out wpnChg[j]); } msg.Read(out equipCount); string[] drpItem = (equipCount > 0) ? new string[equipCount] : null; for (int k = 0; k < equipCount; k++) { msg.Read(out drpItem[k]); } if (seq != MyInfoManager.Instance.Seq) { P2PManager.Instance.Add(seq, ip, port, remoteIp, remotePort, playerflag); BrickManManager.Instance.OnEnter(seq, name, equipment, status, xp, clanSeq, clanName, clanMark, rank, equipment, equipment); BrickManDesc desc = BrickManManager.Instance.GetDesc(seq); desc.Slot = (sbyte)slot; } else { MyInfoManager.Instance.Slot = (sbyte)slot; } } }
public void SendInventoryCSV() { MsgBody body = new MsgBody(); body.Write(inventory.csv._rows.Count); for (int row = 0; row < inventory.csv._rows.Count; row++) { body.Write(inventory.csv._rows[row].Length); for (int col = 0; col < inventory.csv._rows[row].Length; col++) { body.Write(inventory.csv._rows[row][col]); } } Say(ExtensionOpcodes.opInventoryAck, body); }
public Msg2Handle(ushort id, MsgBody msg) { _id = id; _msg = msg; }
public void SetMessage(string msg) { MsgBody.Clear(); MsgBody.SendKeys(msg); }
private void hSockTcpHandleItemListAck(MsgBody msg) { ClientExtension.instance.inventory.Apply(); }
private void HandlePostLoadInit(MsgBody msg) { BrickManager.Instance.userMap.PostLoadInit(); }
private void HandleRequestInventory(MsgBody msg) { msg.Read(out int seq); inventory = new Inventory(seq); SendInventoryCSV(); }
private void HandleCustomMessage(MsgBody msg) { msg.Read(out string message); MessageBoxMgr.Instance.AddMessage(message); }
private void GetSensorReadings() { string pirCurrentState = "U"; EventData eventMessage; //Message message; MsgBody tmpMsg = new MsgBody(msg); try { // Initialize if needed if (pir == null) { // Assume that initialization is needed InitGPIO(); } if (pir != null) { // Only if we are intialized // Get Current IP and MAC (May have changed!) tmpMsg.ID = GetSensorId(); tmpMsg.Ip = GetCurrentIpv4Address(); // Check PIR Status (High == Movement) // if it is high, then motion was detected if (pir.Read() == GpioPinValue.High) { pirCurrentState = "O"; } else { pirCurrentState = "F"; } // Handle state changes with smoothing if (pirCurrentState != state.PendingStatus || state.PendingStatus == "") { // A change. Start counting smoothing time. (Ie time with the same state required for change) state.PendingStatusTime = DateTime.Now; state.PendingStatus = pirCurrentState; } if (state.PendingStatus != tmpMsg.Status && // This is a Status change AND.... (tmpMsg.Status == "" || // this is the first run OR ... (state.PendingStatus == "O" && (DateTime.Now - state.PendingStatusTime).TotalSeconds >= settings.timerStateOSmoothing) || // Pending status is "Occupied" and O-Smoothing-time has passed OR ... (state.PendingStatus == "F" && (DateTime.Now - state.PendingStatusTime).TotalSeconds >= settings.timerStateFSmoothing))) { // Pending status is "Free" and F-Smoothing-time has passed if (state.PendingStatus == "O") { LedSetState(ledRed, true); // Turn on RED LED } else { LedSetState(ledRed, false); // Turn off RED LED } tmpMsg.Status = state.PendingStatus; // Set the new status to the message tmpMsg.Change = "T"; // This is a change of status (T)rue // Create brokered message eventMessage = new EventData(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(tmpMsg))); //*checking message in consoleTONE* Console.WriteLine("{0} > Sending message: {1}", DateTime.Now, JsonConvert.SerializeObject(tmpMsg)); // Send to event hub _eventHub.Send(eventMessage); //SendDeviceToCloudMessagesAsync(tmpMsg); // Save any changes (to this last so that any exception does not save changes.) msg.setMsgBody(tmpMsg); state.LastSendTime = DateTime.Now; // Toggle green led to show a message has been sent LedToggleGreen(); } else if ((DateTime.Now - state.LastSendTime).TotalSeconds > settings.timerKeepAliveIntervall) { // No Change of status. Is it time fot "is alive"? tmpMsg.Change = "F"; // Status change (F)alse. (Set if we will send (is alive) // Create brokered message eventMessage = new EventData(Encoding.ASCII.GetBytes(JsonConvert.SerializeObject(tmpMsg))); //*IotHubTONE* SendDeviceToCloudMessagesAsync(tmpMsg); // Send to IoT hub //private static async void SendDeviceToCloudMessagesAsync(Message m) //{ // await deviceClient.SendEventAsync(m); // Console.WriteLine("{0} > Sending message: {1}", DateTime.Now, messageString); //} _eventHub.Send(eventMessage); // Save any changes (to this last so that any exception does not save changes.) msg.setMsgBody(tmpMsg); state.LastSendTime = DateTime.Now; // Toggle green led to show a message has been sent LedToggleGreen(); } } } catch (Exception exception) { //Status not written } }
public void SendDisconnect() { MsgBody body = new MsgBody(); Say(ExtensionOpcodes.opDisconnectReq, body); }
private void Timer_Tick(object sender, object e) { string pirCurrentState = "U"; MsgBody tmpMsg = new MsgBody(msg); try { // Initialize if needed if (pir == null) { // Assume that initialization is needed InitGPIO(); } if (pir != null) { // Only if we are intialized // Get Current IP and MAC (May have changed!) tmpMsg.ID = GetSensorId(); tmpMsg.Ip = GetCurrentIpv4Address(); // Check PIR Status (High == Movement) // if it is high, then motion was detected if (pir.Read() == GpioPinValue.High) { pirCurrentState = "O"; } else { pirCurrentState = "F"; } // Handle state changes with smoothing if (pirCurrentState != state.PendingStatus || state.PendingStatus == "") { // A change. Start counting smoothing time. (Ie time with the same state required for change) state.PendingStatusTime = DateTime.Now; state.PendingStatus = pirCurrentState; } if (state.PendingStatus != tmpMsg.Status && // This is a Status change AND.... (tmpMsg.Status == "" || // this is the first run OR ... (state.PendingStatus == "x " && (DateTime.Now - state.PendingStatusTime).TotalSeconds >= settings.timerStateOSmoothing) || // Pending status is "Occupied" and O-Smoothing-time has passed OR ... (state.PendingStatus == "F" && (DateTime.Now - state.PendingStatusTime).TotalSeconds >= settings.timerStateFSmoothing))) { // Pending status is "Free" and F-Smoothing-time has passed if (state.PendingStatus == "O") { LedSetState(ledRed, true); // Turn on RED LED LedSetState(ledGreen, false); } else { LedSetState(ledRed, false); // Turn off RED LED LedSetState(ledGreen, true); } tmpMsg.Status = state.PendingStatus; // Set the new status to the message tmpMsg.Change = "T"; // This is a change of status (T)rue tmpMsg.TS = DateTime.Now.ToString(); SendDeviceToCloudMessagesAsync(tmpMsg); // Save any changes (to this last so that any exception does not save changes.) msg.setMsgBody(tmpMsg); state.LastSendTime = DateTime.Now; // Toggle green led to show a message has been sent //LedToggleGreen(); } else if ((DateTime.Now - state.LastSendTime).TotalSeconds > settings.timerKeepAliveIntervall) { // No Change of status. Is it time fot "is alive"? tmpMsg.Change = "F"; // Status change (F)alse. (Set if we will send (is alive) tmpMsg.TS = DateTime.Now.ToString(); // Send message to IoT hub SendDeviceToCloudMessagesAsync(tmpMsg); // Save any changes (to this last so that any exception does not save changes.) msg.setMsgBody(tmpMsg); state.LastSendTime = DateTime.Now; // Toggle green led to show a message has been sent LedToggleGreen(); } } } catch (Exception exception) { //Status not written } //if (Convert.ToString(ReceiveC2dAsync().Result) == "Received") //led.Write(GpioPinValue.Low); }
public void Say(ushort id, MsgBody msgBody) { CSNetManager.Instance.Sock.Say(id, msgBody); }
private void HandleDisconnected(MsgBody msg) { CSNetManager.Instance.Sock.Close(); MessageBoxMgr.Instance.AddMessage(StringMgr.Instance.Get("NETWORK_BROKEN")); BuildOption.Instance.Exit(); }
public MsgBody(MsgBody msg) { setMsgBody(msg); }