Пример #1
0
        /// <summary> Convert item array into network packages and send them to a client </summary>
        public void SendItems(int connectionId, Item[] items, int arraySize)
        {
            /// Create packages while there are unpackaged items left
            int i = 0;

            while (i < arraySize)
            {
                /// Create a package with the max size of maxItemsPerPackage and send it to client
                int    itemsToSendCount = arraySize - i;
                int    packageSize      = itemsToSendCount > maxItemsPerPackage ? maxItemsPerPackage : itemsToSendCount;
                Item[] itemPackage      = new Item[packageSize];

                for (int ii = 0; ii < packageSize; ii++, i++)
                {
                    if (i >= arraySize)
                    {
                        #if DEBUG
                        Debugging.PrintScreen("Error while converting items into packages");
                        #endif
                        break;
                    }
                    if (i >= arraySize)
                    {
                        itemPackage[ii] = items[i];
                    }
                }

                #if DEBUG
                foreach (Item item in itemPackage)
                {
                    if (item == null)
                    {
                        Debugging.PrintScreen("Item in package is null which will cause a serialization error");
                    }
                }
                #endif

                ItemArrayMessage itemArrayMsg = new ItemArrayMessage();
                itemArrayMsg.items = itemPackage;

                NetworkServer.SendToClient(connectionId, NetworkMessageType.AddItems, itemArrayMsg);
            }

            #if DEBUG
            Debugging.PrintScreen("Sent items to client");
            #endif
        }
Пример #2
0
 public void SendToClient(int connectionId, short msgType, MessageBase msg)
 {
     NetworkServer.SendToClient(connectionId, msgType, msg);
 }