Exemplo n.º 1
0
        private async Task <ushort[]> ReadModbusRegistersAsync()
        {
            AllData = await _master.ReadHoldingRegistersAsync(WTX_SLAVE_ADDRESS, WTX_REGISTER_START_ADDRESS, WTX_REGISTER_DATAWORD_COUNT);

            CommunicationLog?.Invoke(this, new LogEventArgs("Read all: " + string.Join(",", AllData.Select(x => x.ToString("X")).ToArray())));
            return(AllData);
        }
        public async Task <IActionResult> PutCommunicationLog(int id, CommunicationLog communicationLog)
        {
            if (id != communicationLog.Id)
            {
                return(BadRequest());
            }

            _context.Entry(communicationLog).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CommunicationLogExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <ActionResult <CommunicationLog> > PostCommunicationLog(CommunicationLog communicationLog)
        {
            _context.CommunicationLogs.Add(communicationLog);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetCommunicationLog", new { id = communicationLog.Id }, communicationLog));
        }
Exemplo n.º 4
0
        /// <summary>
        /// //Tells a client where all the active entities are in the world to have them spawned in before they can enter the game world
        /// </summary>
        /// <param name="ClientID">NetworkID for target client</param>
        public static void SendActiveEntityList(int ClientID)
        {
            CommunicationLog.LogOut(ClientID + " active entity list");

            //Create a new NetworkPacket object to store the data for this active entity list
            NetworkPacket Packet = new NetworkPacket();

            //Grab the list of all the entities currently active in the game world
            List <BaseEntity> ActiveEntities = EntityManager.ActiveEntities;

            //Write the relevant data values into the packet data
            Packet.WriteType(ServerPacketType.ActiveEntityList);
            Packet.WriteInt(ActiveEntities.Count);

            //Loop through the list of active entities and write each of their information into the packet data
            foreach (BaseEntity ActiveEntity in ActiveEntities)
            {
                Packet.WriteString(ActiveEntity.Type);
                Packet.WriteString(ActiveEntity.ID);
                Packet.WriteVector3(VectorTranslate.ConvertVector(ActiveEntity.Location));
                Packet.WriteInt(ActiveEntity.HealthPoints);
            }

            //Add this packet to the target clients outgoing packet queue
            PacketQueue.QueuePacket(ClientID, Packet);
        }
Exemplo n.º 5
0
        /// <summary>
        /// //Tells a client where all the other players are in the world so they can be spawned in before they can enter the world
        /// </summary>
        /// <param name="ClientID">NetworkID for target client</param>
        public static void SendActivePlayerList(int ClientID)
        {
            CommunicationLog.LogOut(ClientID + " active player list");

            //Create a new NetworkPacket object to store the data for this active player list
            NetworkPacket Packet = new NetworkPacket();

            //Grab the list of all the other active game clients
            List <ClientConnection> OtherClients = ClientSubsetFinder.GetInGameClientsExceptFor(ClientID);

            //Write the relevant data values into the packet data
            Packet.WriteType(ServerPacketType.ActivePlayerList);
            Packet.WriteInt(OtherClients.Count);

            //Loop through the list of other clients and write each of their information into the packet data
            foreach (ClientConnection OtherClient in OtherClients)
            {
                //Write each characters name, and current location and rotation values
                Packet.WriteString(OtherClient.Character.Name);
                Packet.WriteBool(OtherClient.Character.IsAlive);
                Packet.WriteVector3(OtherClient.Character.Position);
                Packet.WriteQuaternion(OtherClient.Character.Rotation);
                Packet.WriteInt(OtherClient.Character.CurrentHealth);
                Packet.WriteInt(OtherClient.Character.MaxHealth);
            }

            //Add this packet to the target clients outgoing packet queue
            PacketQueue.QueuePacket(ClientID, Packet);
        }
Exemplo n.º 6
0
        public static void HandleClientChatMessage(int ClientID, ref NetworkPacket Packet)
        {
            CommunicationLog.LogIn(ClientID + " chat message");

            //Fetch this ClientConnection and make sure they were able to be found
            ClientConnection Client = ConnectionManager.GetClient(ClientID);

            if (Client == null)
            {
                MessageLog.Print("ERROR: Client not found, unable to handle chat message.");
                return;
            }

            //Extract the message content from the network packet
            string ChatMessage = Packet.ReadString();

            //Get the list of all the other game clients who are already ingame
            List <ClientConnection> OtherClients = ClientSubsetFinder.GetInGameClientsExceptFor(ClientID);

            //Pass this chat message on to all the other clients that are ingame
            foreach (ClientConnection OtherClient in OtherClients)
            {
                PlayerCommunicationPacketSender.SendChatMessage(OtherClient.ClientID, Client.Character.Name, ChatMessage);
            }
        }
Exemplo n.º 7
0
        //When a client wants to enter the game world, we need to send them a bunch of information to set up their game world before they can enter
        public static void HandleEnterWorldRequest(int ClientID, ref NetworkPacket Packet)
        {
            CommunicationLog.LogIn(ClientID + " enter world request");

            //Read the characters name the player is going to use, use it to fetch the rest of the characters data from the database
            string        CharacterName = Packet.ReadString();
            CharacterData CharacterData = CharactersDatabase.GetCharacterData(CharacterName);

            //Fetch this ClientConnection and make sure they were able to be found
            ClientConnection Client = ConnectionManager.GetClient(ClientID);

            if (Client == null)
            {
                MessageLog.Print("ERROR: Client not found, unable to handle enter world request.");
                return;
            }

            //Store the character data in the client
            Client.Character = CharacterData;

            //Send the clients lists of other players, AI entities, item pickups, inventory contents, equipped items and socketed actionbar abilities
            GameWorldStatePacketSender.SendActivePlayerList(ClientID);
            GameWorldStatePacketSender.SendActiveEntityList(ClientID);
            GameWorldStatePacketSender.SendActiveItemList(ClientID);
            GameWorldStatePacketSender.SendInventoryContents(ClientID, CharacterName);
            GameWorldStatePacketSender.SendEquippedItems(ClientID, CharacterName);
            GameWorldStatePacketSender.SendSocketedAbilities(ClientID, CharacterName);
        }
Exemplo n.º 8
0
        public async Task <IActionResult> Edit(int id, [Bind("CommunicationLogId,CommunicationDate,CommunicationType,Notes")] CommunicationLog communicationLog)
        {
            if (id != communicationLog.CommunicationLogId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(communicationLog);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CommunicationLogExists(communicationLog.CommunicationLogId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(PartialView(communicationLog));
        }
Exemplo n.º 9
0
        /// <summary>
        /// Event will be called when device sends new fetch events
        /// </summary>
        /// <param name="data">New device data from jet peer</param>
        private void OnFetchData(JToken data)
        {
            string path = data["path"].ToString();

            lock (AllData)
            {
                switch (data["event"].ToString())
                {
                case "add":
                    AllData.Add(path, data["value"].ToString());
                    break;

                case "fetch":
                    AllData[path] = data["value"].ToString();
                    break;

                case "change":
                    AllData[path] = data["value"].ToString();
                    break;
                }

                if (IsConnected)
                {
                    this.UpdateData?.Invoke(this, new EventArgs());
                }

                CommunicationLog?.Invoke(this, new LogEventArgs(data.ToString()));
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// //Tells a clients all the contents of their chosen characters inventory to be loaded in before they enter into the game world
        /// </summary>
        /// <param name="ClientID">NetworkID of target client</param>
        /// <param name="CharacterName">Name of character who's inventory contents are being sent</param>
        public static void SendInventoryContents(int ClientID, string CharacterName)
        {
            CommunicationLog.LogOut(ClientID + " inventory contents");

            //Create a new NetworkPacket object to store the data for this inventory contents request
            NetworkPacket Packet = new NetworkPacket();

            //Grab the list of all the items currently in the characters inventory
            List <ItemData> InventoryContents = InventoriesDatabase.GetAllInventorySlots(CharacterName);

            //Write the relevant data values into the packet data
            Packet.WriteType(ServerPacketType.InventoryContents);

            Packet.WriteInt(0);
            PacketQueue.QueuePacket(ClientID, Packet);

            //Packet.WriteInt(InventoryContents.Count);

            ////Loop through the list of items in the players inventory and write all of their information into the packet data
            //foreach(ItemData Item in InventoryContents)
            //{
            //    Packet.WriteInt(Item.ItemNumber);
            //    Packet.WriteInt(Item.ItemID);
            //}

            ////Add this packet to the target clients outgoing packet queue
            //PacketQueue.QueuePacket(ClientID, Packet);
        }
Exemplo n.º 11
0
        public async Task <string> SendAsync(string messageToSend)
        {
            await SendLock.WaitAsync();

            try
            {
                CommunicationLog.RawMessageSending(messageToSend);
                await SendAsync(ClientWriter, messageToSend);

                CommunicationLog.RawMessageSent(messageToSend);

                do
                {
                    if (MessageResponses.TryDequeue(out var result))
                    {
                        return(result);
                    }

                    await Task.Delay(TimeSpan.FromMilliseconds(10)).ConfigureAwait(false);
                } while (Connected);

                return(null);
            }
            finally
            {
                SendLock.Release();
            }
        }
Exemplo n.º 12
0
        /// <summary>
        /// //Tells a client where all the active items are in the world to have them spawned in before they can start playing
        /// </summary>
        /// <param name="ClientID">NetworkID for target client</param>
        public static void SendActiveItemList(int ClientID)
        {
            CommunicationLog.LogOut(ClientID + " active item list");

            //Create a new NetworkPacket object to store the data for this active item list
            NetworkPacket Packet = new NetworkPacket();

            //Grab the list of all the active item pickups currently in the game world
            List <GameItem> ItemPickups = ItemManager.GetActiveItemList();

            //Write the relevant data values into the packet data
            Packet.WriteType(ServerPacketType.ActiveItemList);
            Packet.WriteInt(ItemPickups.Count);

            //Loop through the list of item pickups and write each of their information into the packet data
            foreach (GameItem ItemPickup in ItemPickups)
            {
                Packet.WriteInt(ItemPickup.ItemNumber);
                Packet.WriteInt(ItemPickup.ItemID);
                Packet.WriteVector3(VectorTranslate.ConvertVector(ItemPickup.ItemPosition));
            }

            //Add this packet to the target clients outgoing packet queue
            PacketQueue.QueuePacket(ClientID, Packet);
        }
Exemplo n.º 13
0
        /// <summary>
        /// Event with callend when raced a Fetch-Event by a other Peer.
        /// For testing it must be filled with pseudo data be tested in the UNIT tests.
        /// </summary>
        /// <param name="data"></param>
        public void OnFetchData(JToken data)
        {
            string path  = data["path"].ToString();
            string Event = data["Event"].ToString();

            lock (_dataBuffer)
            {
                switch (Event)
                {
                case "add":
                    _dataBuffer.Add(path, data["value"]);

                    break;

                case "fetch":
                    _dataBuffer[path] = data["value"];

                    break;

                case "change":
                    _dataBuffer[path] = data["value"];

                    break;
                }

                if (IsConnected)
                {
                    this.UpdateData?.Invoke(this, new EventArgs());
                }

                CommunicationLog?.Invoke(this, new LogEventArgs(data.ToString()));
            }
        }
Exemplo n.º 14
0
        /// <summary>
        /// Handles a client players updated camera values to be stored in their ClientConnection, until
        /// they either leave or the server is being shutdown, to then be backed up into the database
        /// </summary>
        /// <param name="ClientID">NetworkID of the target client</param>
        /// <param name="Packet">Packet containing the information were after</param>
        public static void HandlePlayerCameraUpdate(int ClientID, ref NetworkPacket Packet)
        {
            //Log what we are doing here
            CommunicationLog.LogIn(ClientID + " Player Camera Update");

            //Extract all the values from the packet data
            float Zoom      = Packet.ReadFloat();
            float XRotation = Packet.ReadFloat();
            float YRotation = Packet.ReadFloat();

            //Try getting the ClientConnection object who sent this packet to us
            ClientConnection Client = ConnectionManager.GetClient(ClientID);

            //Display an error and exit from the function if they couldnt be found
            if (Client == null)
            {
                MessageLog.Print("ERROR: " + ClientID + " ClientConnection object couldnt be found, Player Camera Update could not be performed.");
                return;
            }

            //Store them in the ClientConnection object
            Client.Character.CameraZoom      = Zoom;
            Client.Character.CameraXRotation = XRotation;
            Client.Character.CameraYRotation = YRotation;
        }
Exemplo n.º 15
0
        /// <summary>
        /// //Tells a client all the items currently equipped on their chosen character to be loaded in before they enter into the game world
        /// </summary>
        /// <param name="ClientID">NetworkID of target client</param>
        /// <param name="CharacterName">Name of character who's equipped items are being sent</param>
        public static void SendEquippedItems(int ClientID, string CharacterName)
        {
            CommunicationLog.LogOut(ClientID + " equipped items");

            //Create a new NetworkPacket object to store the data for this equipped items request
            NetworkPacket Packet = new NetworkPacket();

            //Grab the list of all the items currently equipped on the character
            List <ItemData> EquippedItems = EquipmentsDatabase.GetAllEquipmentSlots(CharacterName);

            //Write the relevant data values into the packet data
            Packet.WriteType(ServerPacketType.EquippedItems);

            Packet.WriteInt(0);
            PacketQueue.QueuePacket(ClientID, Packet);

            //Packet.WriteInt(EquippedItems.Count);

            ////Loop through the list and write in each items information into the packet data
            //foreach(ItemData Item in EquippedItems)
            //{
            //    Packet.WriteInt((int)Item.ItemEquipmentSlot);
            //    Packet.WriteInt(Item.ItemNumber);
            //    Packet.WriteInt(Item.ItemID);
            //}

            ////Add this packet to the target clients outgoing packet queue
            //PacketQueue.QueuePacket(ClientID, Packet);
        }
Exemplo n.º 16
0
        /// <summary>
        /// //Tells a client all the items currently socketed into their ability bar to be loaded in before they can enter into the game world
        /// </summary>
        /// <param name="ClientID">NetworkID of target client</param>
        /// <param name="CharacterName">Name of character who's socketed abilities are being sent</param>
        public static void SendSocketedAbilities(int ClientID, string CharacterName)
        {
            CommunicationLog.LogOut(ClientID + " socketed abilities");

            //Create a new NetworkPacket object to store the data for this socketed abilities request
            NetworkPacket Packet = new NetworkPacket();

            //Grab the list of all the items currently socketed into the characters action bar
            List <ItemData> SocketedAbilities = ActionBarsDatabase.GetEveryActionBarItem(CharacterName);

            //Write the relevant data values into the packet data
            Packet.WriteType(ServerPacketType.SocketedAbilities);

            Packet.WriteInt(0);
            PacketQueue.QueuePacket(ClientID, Packet);

            //Packet.WriteInt(SocketedAbilities.Count);

            ////Loop through the list and write in each items information into the packet data
            //foreach(ItemData Ability in SocketedAbilities)
            //{
            //    Packet.WriteInt(Ability.ItemNumber);
            //    Packet.WriteInt(Ability.ItemID);
            //}

            ////Add this packet to the target clients outgoing packet queue
            //PacketQueue.QueuePacket(ClientID, Packet);
        }
Exemplo n.º 17
0
        /// <summary>
        /// //Asks a client if they are still connected, requesting for them to immediately reply to us letting us know
        /// </summary>
        /// <param name="ClientID">NetworkID of the target client</param>
        public static void SendStillConnectedCheck(int ClientID)
        {
            CommunicationLog.LogOut(ClientID + " still alive request");
            NetworkPacket Packet = new NetworkPacket();

            Packet.WriteType(ServerPacketType.StillConnectedCheck);
            PacketQueue.QueuePacket(ClientID, Packet);
        }
Exemplo n.º 18
0
        //Tells a client their character is now dead so it turns into a ragdoll and they lose control
        public static void SendLocalPlayerDead(int ClientID)
        {
            CommunicationLog.LogOut(ClientID + " Local Player Dead");
            NetworkPacket Packet = new NetworkPacket();

            Packet.WriteType(ServerPacketType.LocalPlayerDead);
            PacketQueue.QueuePacket(ClientID, Packet);
        }
Exemplo n.º 19
0
        /// <summary>
        /// //Sends a message to a client letting them know we have missed some packets and need them to be resent to us again
        /// </summary>
        /// <param name="ClientID">NetworkID of the target client</param>
        /// <param name="FirstMissedPacket">Number of the first packet you need resent, all the way to the last</param>
        public static void SendMissingPacketsRequest(int ClientID, int FirstMissedPacket)
        {
            CommunicationLog.LogOut(ClientID + " Missing Packets Request.");
            NetworkPacket Packet = new NetworkPacket();

            Packet.WriteType(ServerPacketType.MissingPacketsRequest);
            Packet.WriteInt(FirstMissedPacket);
            PacketQueue.QueuePacket(ClientID, Packet);
        }
Exemplo n.º 20
0
        //Tells a client to update their players character with a new HP value
        public static void SendLocalPlayerTakeHit(int ClientID, int NewHPValue)
        {
            CommunicationLog.LogOut(ClientID + " local player take hit alert");
            NetworkPacket Packet = new NetworkPacket();

            Packet.WriteType(ServerPacketType.LocalPlayerTakeHit);
            Packet.WriteInt(NewHPValue);
            PacketQueue.QueuePacket(ClientID, Packet);
        }
Exemplo n.º 21
0
 /// <summary>
 /// Closes the Modbus/TCP connection
 /// </summary>
 public void Disconnect()
 {
     if (_client != null)
     {
         _client.Close();
     }
     IsConnected = false;
     CommunicationLog?.Invoke(this, new LogEventArgs("Disconnected"));
 }
Exemplo n.º 22
0
        //Tells a client to update some remote players character as being dead, so it turn into a ragdoll
        public static void SendRemotePlayerDead(int ClientID, string CharacterName)
        {
            CommunicationLog.LogOut(ClientID + " Remote Player Dead");
            NetworkPacket Packet = new NetworkPacket();

            Packet.WriteType(ServerPacketType.RemotePlayerDead);
            Packet.WriteString(CharacterName);
            PacketQueue.QueuePacket(ClientID, Packet);
        }
Exemplo n.º 23
0
        /// <summary>
        /// //Tells a client they have been added into the game world physics simulation and they may now start playing
        /// </summary>
        /// <param name="ClientID">NetworkID of the target client</param>
        public static void SendPlayerBegin(int ClientID)
        {
            CommunicationLog.LogOut(ClientID + " player begin");

            NetworkPacket Packet = new NetworkPacket();

            Packet.WriteType(ServerPacketType.AllowPlayerBegin);
            PacketQueue.QueuePacket(ClientID, Packet);
        }
Exemplo n.º 24
0
        public static void SendPlayAnimationAlert(int ClientID, string CharacterName, string AnimationName)
        {
            CommunicationLog.LogOut(ClientID + " play animation alert");
            NetworkPacket Packet = new NetworkPacket();

            Packet.WriteType(ServerPacketType.PlayAnimationAlert);
            Packet.WriteString(CharacterName);
            Packet.WriteString(AnimationName);
            PacketQueue.QueuePacket(ClientID, Packet);
        }
Exemplo n.º 25
0
        //Tells a client to update some remote players character with a new HP value
        public static void SendRemotePlayerTakeHit(int ClientID, string CharacterName, int NewHPValue)
        {
            CommunicationLog.LogOut(ClientID + " remote player take hit alert");
            NetworkPacket Packet = new NetworkPacket();

            Packet.WriteType(ServerPacketType.RemotePlayerTakeHit);
            Packet.WriteString(CharacterName);
            Packet.WriteInt(NewHPValue);
            PacketQueue.QueuePacket(ClientID, Packet);
        }
Exemplo n.º 26
0
        /// <summary>
        /// 处理缓冲区
        /// </summary>
        /// <param name="buf"></param>
        /// <returns></returns>
        public override byte[] DataInDeal(byte[] buf)
        {
            var ch = new CommunicationLog
            {
                ComDirect = 1,
                ValueByte = buf
            };

            this.CommHis.Add(ch);
            return(buf);
        }
Exemplo n.º 27
0
        //Tells a client to respawn some other remote players character into the game world with all these values
        public static void SendRemotePlayerRespawn(int ClientID, CharacterData Data)
        {
            CommunicationLog.LogOut(ClientID + " Remote Player Respawn");
            NetworkPacket Packet = new NetworkPacket();

            Packet.WriteType(ServerPacketType.RemotePlayerRespawn);
            Packet.WriteString(Data.Name);
            Packet.WriteVector3(Data.Position);
            Packet.WriteQuaternion(Data.Rotation);
            PacketQueue.QueuePacket(ClientID, Packet);
        }
Exemplo n.º 28
0
        public async Task <IActionResult> Create([Bind("CommunicationLogId,CommunicationDate,CommunicationType,Notes")] CommunicationLog communicationLog)
        {
            if (ModelState.IsValid)
            {
                _context.Add(communicationLog);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(PartialView(communicationLog));
        }
Exemplo n.º 29
0
        private void OnSet(bool success, JToken token)
        {
            if (!success)
            {
                _localException = new JetBusException(token);
            }

            _successEvent.Set();

            CommunicationLog?.Invoke(this, new LogEventArgs("Set data" + success));
        }
Exemplo n.º 30
0
        //Handles a users account logout alert
        public static void HandleAccountLogoutAlert(int ClientID, ref NetworkPacket Packet)
        {
            //Log what we are doing here
            CommunicationLog.LogIn(ClientID + " Account Logout Alert.");

            //Get the client who is logged out
            ClientConnection Client = ConnectionManager.GetClient(ClientID);

            //Clear them as being logged in to any account
            Client.Account = new AccountData();
        }