示例#1
0
        protected void Broadcast(BroadcastMessageType type, int var1, int var2, int var3)
        {
            if (!_wrapper.IsConnected)
            {
                return;
            }

            _wrapper.BroadcastMessage(type, var1, var2, var3);
        }
        public static void BroadcastMessage(BroadcastMessageType msg, int var1, int var2)
        {
            var msgId         = GetBroadcastMessageId();
            var hwndBroadcast = IntPtr.Add(IntPtr.Zero, 0xffff);

            if (msgId != IntPtr.Zero)
            {
                NativeMethods.SendNotifyMessage(hwndBroadcast, msgId.ToInt32(), MakeLong((short)msg, (short)var1), var2);
            }
        }
示例#3
0
        public int BroadcastMessage(BroadcastMessageType msg, int var1, int var2)
        {
            IntPtr msgId         = GetBroadcastMessageID();
            IntPtr hwndBroadcast = IntPtr.Add(IntPtr.Zero, 0xffff);
            IntPtr result        = IntPtr.Zero;

            if (msgId != IntPtr.Zero)
            {
                result = PostMessage(hwndBroadcast, msgId.ToInt32(), MakeLong((short)msg, (short)var1), var2);
            }
            return(result.ToInt32());
        }
示例#4
0
        public void Copy(BroadcastMessageDataObject _object)
        {
            if (_object == null)
            {
                return;
            }

            base.Copy(_object);

            Type             = _object.Type;
            Command          = _object.Command;
            TargetGameObject = _object.TargetGameObject;
            BahaviourKey     = _object.BahaviourKey;
        }
示例#5
0
        public void SendBroadcastMessage(BroadcastMessageType msgType, ISerialiser <AutoDiscoveryMessage, byte[]> serialiser, Int32 multicastPort)
        {
            if (msgType == BroadcastMessageType.None)
            {
                throw new InvalidOperationException("The specified BroadcastMessageType is not valid");
            }

            if (serialiser == null)
            {
                throw new ArgumentException("The specified serialiser is not valid");
            }

            // Create and prepare the arguments
            byte[] temp = serialiser.Serialise(new AutoDiscoveryMessage(_socket.LocalEndPoint, msgType));
            byte[] data = BitConverter.GetBytes(temp.Length).Merge(temp);
            // send the data
            UdpClient cli = new UdpClient();

            cli.Send(data, data.Length, new IPEndPoint(IPAddress.Broadcast, Port));
        }
示例#6
0
        /// <summary>
        /// Broadcasts message to all sessions after sending messages to the both associated sessions (Buddy pair).
        /// Then it also broacasts messages to all other session based on the the response type so that they can update
        /// their's buddyList.
        /// </summary>
        /// <param name="responseType">Broadcast message type.</param>
        /// <param name="currentService">Current service instance.</param>
        /// <param name="destinationService">Destination service instance.</param>
        /// <param name="responseToCurrentService">Message to be sent to the currentService.</param>
        /// <param name="responseToDestinationservice">Message to be sent to the destinationService.</param>
        public void BroadcastMessage(BroadcastMessageType responseType, GameService currentService, GameService destinationService, string responseToCurrentService, string responseToDestinationservice)
        {
            if (null != currentService)
            {
                this.SendMessage(currentService, responseToCurrentService);
            }

            if (null != destinationService)
            {
                this.SendMessage(destinationService, responseToDestinationservice);
            }

            List<GameService> defunctServiceList = null;

            // Now also send this to other players who are not playing.
            this.thisLock.EnterReadLock();
            try
            {
                foreach (var service in this.innerCache)
                {
                    // Find out logged in users excluding destination service.
                    if (!string.IsNullOrEmpty(service.Context.LogOnName)
                        && service != currentService && service != destinationService)
                    {
                        switch (responseType)
                        {
                            case BroadcastMessageType.LogOnResponse:
                                if (null == service.Context.BuddyInstance)
                                {
                                    Send(service, "JoinBuddyList:" + currentService.Context.LogOnName, defunctServiceList);
                                }

                                break;

                            case BroadcastMessageType.SelectBuddyResponse:
                                if (null == service.Context.BuddyInstance)
                                {
                                    Send(service, "RemoveFromBuddyList:" + currentService.Context.LogOnName + ";" + destinationService.Context.LogOnName, defunctServiceList);
                                }

                                break;
                            case BroadcastMessageType.GameCompleteResponse:
                                if (null == service.Context.BuddyInstance)
                                {
                                    Send(service, "JoinBuddyList:" + currentService.Context.LogOnName + ";" + destinationService.Context.LogOnName, defunctServiceList);
                                }

                                break;

                            case BroadcastMessageType.LogOffResponse:
                                // Now this string has \" char at front and back both.
                                string[] defunctServiceResponse = responseToCurrentService.ToString().Split(new char[] { ':' });

                                // Remove quotes from the end of this string.
                                string defunctServiceName = defunctServiceResponse[1].Substring(0, defunctServiceResponse[1].Length - 1);
                                Send(service, "RemoveFromBuddyList:" + defunctServiceName, defunctServiceList);

                                // Also tell services to join defunct's buddy in their buddyList as it is no more playing with anyone.
                                if ((null != currentService) && !string.IsNullOrEmpty(currentService.Context.LogOnName))
                                {
                                    Send(service, "JoinBuddyList:" + currentService.Context.LogOnName, defunctServiceList);
                                }

                                break;
                        }
                    }
                }
            }
            finally
            {
                this.thisLock.ExitReadLock();
            }

            // Now look at the defunctService list and take te appropriate action.
            if (null != defunctServiceList)
            {
                // Each pair is made of service name and it's buddy service instance.
                Dictionary<string, GameService> defunctBuddyPairs = null;

                this.thisLock.EnterWriteLock();
                try
                {
                    foreach (var entry in defunctServiceList)
                    {
                        GameService buddyInstance = entry.Context.BuddyInstance;
                        string defunctName = entry.Context.LogOnName;

                        this.innerCache.Remove(entry);

                        if (null != buddyInstance && !string.IsNullOrEmpty(defunctName))
                        {
                            if (null == defunctBuddyPairs)
                            {
                                defunctBuddyPairs = new Dictionary<string, GameService>();
                            }

                            defunctBuddyPairs.Add(defunctName, buddyInstance);
                        }
                    }
                }
                finally
                {
                    this.thisLock.ExitWriteLock();
                }

                if (null != defunctBuddyPairs)
                {
                    foreach (KeyValuePair<string, GameService> buddyPair in defunctBuddyPairs)
                    {
                        this.RemoveBuddyPair(buddyPair.Key, buddyPair.Value);
                    }
                }
            }
        }
示例#7
0
 public int BroadcastMessage(BroadcastMessageType msg, int var1, int var2, int var3)
 {
     return(BroadcastMessage(msg, var1, MakeLong((short)var2, (short)var3)));
 }
示例#8
0
 public BroadcastMessageDataObject(BroadcastMessageType _type, GameObject _target, string _command)
 {
     Type             = _type;
     TargetGameObject = _target;
     Command          = _command;
 }
示例#9
0
        /// <summary>
        /// Broadcasts message to all sessions after sending messages to the both associated sessions (Buddy pair).
        /// Then it also broacasts messages to all other session based on the the response type so that they can update
        /// their's buddyList.
        /// </summary>
        /// <param name="responseType">Broadcast message type.</param>
        /// <param name="currentService">Current service instance.</param>
        /// <param name="destinationService">Destination service instance.</param>
        /// <param name="responseToCurrentService">Message to be sent to the currentService.</param>
        /// <param name="responseToDestinationservice">Message to be sent to the destinationService.</param>
        public void BroadcastMessage(BroadcastMessageType responseType, JigsawGameService currentService, JigsawGameService destinationService, string responseToCurrentService, string responseToDestinationservice)
        {
            if (null != currentService)
            {
                this.SendMessage(currentService, responseToCurrentService);
            }

            if (null != destinationService)
            {
                this.SendMessage(destinationService, responseToDestinationservice);
            }

            List <JigsawGameService> defunctServiceList = null;

            // Now also send this to other players who are not playing.
            this.thisLock.EnterReadLock();
            try
            {
                foreach (var service in this.innerCache)
                {
                    // Find out logged in users excluding destination service.
                    if (!string.IsNullOrEmpty(service.Context.LogOnName) &&
                        service != currentService && service != destinationService)
                    {
                        switch (responseType)
                        {
                        case BroadcastMessageType.LogOnResponse:
                            if (null == service.Context.PlayerInstance)
                            {
                                Send(service, "JoinPlayerList:" + currentService.Context.LogOnName, defunctServiceList);
                            }

                            break;

                        case BroadcastMessageType.SelectPlayerResponse:
                            if (null == service.Context.PlayerInstance)
                            {
                                Send(service, "RemoveFromPlayerList:" + currentService.Context.LogOnName + ";" + destinationService.Context.LogOnName, defunctServiceList);
                            }

                            break;

                        case BroadcastMessageType.GameCompleteResponse:
                            if (null == service.Context.PlayerInstance)
                            {
                                Send(service, "JoinPlayerList:" + currentService.Context.LogOnName + ";" + destinationService.Context.LogOnName, defunctServiceList);
                            }

                            break;

                        case BroadcastMessageType.LogOffResponse:
                            // Now this string has \" char at front and back both.
                            string[] defunctServiceResponse = responseToCurrentService.ToString().Split(new char[] { ':' });

                            // Remove quotes from the end of this string.
                            string defunctServiceName = defunctServiceResponse[1].Substring(0, defunctServiceResponse[1].Length - 1);
                            Send(service, "RemoveFromPlayerList:" + defunctServiceName, defunctServiceList);

                            // Also tell services to join defunct's player in their playerList as it is no more playing with anyone.
                            if ((null != currentService) && !string.IsNullOrEmpty(currentService.Context.LogOnName))
                            {
                                Send(service, "JoinPlayerList:" + currentService.Context.LogOnName, defunctServiceList);
                            }

                            break;
                        }
                    }
                }
            }
            finally
            {
                this.thisLock.ExitReadLock();
            }

            // Now look at the defunctService list and take te appropriate action.
            if (null != defunctServiceList)
            {
                // Each pair is made of service name and it's player service instance.
                Dictionary <string, JigsawGameService> defunctPlayerPairs = null;

                this.thisLock.EnterWriteLock();
                try
                {
                    foreach (var entry in defunctServiceList)
                    {
                        JigsawGameService playerInstance = entry.Context.PlayerInstance;
                        string            defunctName    = entry.Context.LogOnName;

                        this.innerCache.Remove(entry);

                        if (null != playerInstance && !string.IsNullOrEmpty(defunctName))
                        {
                            if (null == defunctPlayerPairs)
                            {
                                defunctPlayerPairs = new Dictionary <string, JigsawGameService>();
                            }

                            defunctPlayerPairs.Add(defunctName, playerInstance);
                        }
                    }
                }
                finally
                {
                    this.thisLock.ExitWriteLock();
                }

                if (null != defunctPlayerPairs)
                {
                    foreach (KeyValuePair <string, JigsawGameService> playerPair in defunctPlayerPairs)
                    {
                        this.RemovePlayerPair(playerPair.Key, playerPair.Value);
                    }
                }
            }
        }
示例#10
0
 public AutoDiscoveryMessage(EndPoint ip, BroadcastMessageType msgType = BroadcastMessageType.None)
 {
     MessageType = msgType;
     Ip          = (IPEndPoint)ip;
 }
 public static void BroadcastMessage(BroadcastMessageType msg, int var1, int var2, int var3)
 {
     BroadcastMessage(msg, var1, MakeLong((short)var2, (short)var3));
 }
示例#12
0
 internal int BroadcastMessage(BroadcastMessageType msg, int var1, int var2, int var3)
 {
     return(sdk.BroadcastMessage(msg, var1, var2, var3));
 }
示例#13
0
 public BroadcastMessageTypeAttribute(BroadcastMessageType messageType)
 {
     MessageType = messageType;
 }
示例#14
0
 public static Type GetTypeForMessageType(BroadcastMessageType messageType)
 {
     return(_typeMapping.GetTypeForKey(messageType));
 }
示例#15
0
        private async Task PostInfo(string url, string serializeObject, BroadcastType broadcastType, BroadcastMessageType broadcastMessageType)
        {
            var context = $"{broadcastType} - {broadcastMessageType}";

            try
            {
                var result = await _httpClient.PostAsync(url, new StringContent(serializeObject, Encoding.UTF8, "application/json"));

                await _log.WriteInfoAsync(ComponentName, context, JsonConvert.SerializeObject(new
                {
                    url,
                    result.StatusCode,
                    reuqest = serializeObject,
                    body    = await result.Content.ReadAsStringAsync()
                }));
            }
            catch (Exception ex)
            {
                await _log.WriteWarningAsync(ComponentName, context, JsonConvert.SerializeObject(new
                {
                    url,
                    reuqest = serializeObject
                }), ex);
            }
        }