コード例 #1
0
        /// <summary>
        /// Is called when the voting receiver receives a message
        /// </summary>
        private void OnVoteReceiverMessage(object sender, OnMessageArgs e)
        {
            if (!voteRunning)
            {
                return;
            }

            if (permittedUsernames.Length > 0)
            {
                bool found = false;

                foreach (string name in permittedUsernames)
                {
                    // both have already been lowered in other methods, so this comparison is always case-insensitive
                    if (name == e.Username)
                    {
                        found = true;
                        break;
                    }
                }

                if (!found)
                {
                    return;
                }
            }

            for (int i = 0; i < activeVoteOptions.Count; i++)
            {
                var voteOption = activeVoteOptions[i];

                if (voteOption.Matches.Contains(e.Message))
                {
                    int previousVote;

                    // Check if the player has already voted
                    if (!userVotedFor.TryGetValue(e.ClientId, out previousVote))
                    {
                        // If they haven't voted, count his vote
                        userVotedFor.Add(e.ClientId, i);
                        voteOption.Votes++;
                    }
                    else if (previousVote != i)
                    {
                        // If the player has already voted, and it's not the same as before,
                        // remove the old vote, and add the new one.
                        userVotedFor.Remove(e.ClientId);
                        activeVoteOptions[previousVote].Votes--;

                        userVotedFor.Add(e.ClientId, i);
                        voteOption.Votes++;
                    }

                    break;
                }
            }
        }
コード例 #2
0
 private void ISCServer_OnMessage(object s, OnMessageArgs e)
 {
     if (e.ID == 99)
     {
         int charid = BitConverter.ToInt32(e.Data, 0);
         foreach (Client c in Program.zoneServer.Clients)
         {
             if (c.Character.Id == charid)
             {
                 Console.ForegroundColor = ConsoleColor.Red;
                 Console.WriteLine("Unauthorized access detected: \r\nCharacterID: " + charid);
                 Console.WriteLine("From IP: " + c.TcpIP);
                 Console.ForegroundColor = ConsoleColor.Gray;
                 Program.zoneServer.DisconnectClient(c);
                 break;
             }
         }
     }
 }
コード例 #3
0
ファイル: ISCServer.cs プロジェクト: semirs1991/CellAO
 private void ISCServer_OnMessage(object s, OnMessageArgs e)
 {
     if (e.ID == 99)
     {
         int charid = BitConverter.ToInt32(e.Data, 0);
         foreach (Client c in Program.zoneServer.Clients)
         {
             if (c.Character.Id == charid)
             {
                 Console.ForegroundColor = ConsoleColor.Red;
                 Console.WriteLine("Unauthorized access detected: \r\nCharacterID: " + charid);
                 Console.WriteLine("From IP: " + c.TcpIP);
                 Console.ForegroundColor = ConsoleColor.Gray;
                 Program.zoneServer.DisconnectClient(c);
                 break;
             }
         }
     }
 }
コード例 #4
0
        /// <summary>
        /// Is called when the voting receiver receives a message
        /// </summary>
        private void OnVoteReceiverMessage(object sender, OnMessageArgs e)
        {
            if (!voteRunning)
            {
                return;
            }

            for (int i = 0; i < activeVoteOptions.Count; i++)
            {
                var voteOption = activeVoteOptions[i];

                if (voteOption.Matches.Contains(e.Message))
                {
                    int previousVote;

                    // Check if the player has already voted
                    if (!userVotedFor.TryGetValue(e.ClientId, out previousVote))
                    {
                        // If they haven't voted, count his vote
                        userVotedFor.Add(e.ClientId, i);
                        voteOption.Votes++;
                    }
                    else if (previousVote != i)
                    {
                        // If the player has already voted, and it's not the same as before,
                        // remove the old vote, and add the new one.
                        userVotedFor.Remove(e.ClientId);
                        activeVoteOptions[previousVote].Votes--;

                        userVotedFor.Add(e.ClientId, i);
                        voteOption.Votes++;
                    }

                    break;
                }
            }
        }
コード例 #5
0
 /// <summary>
 /// </summary>
 /// <param name="request">
 /// </param>
 /// <param name="onMessageArgs">
 /// </param>
 private void ClientMessage(object request, OnMessageArgs onMessageArgs)
 {
     this.MessageReceived(request, onMessageArgs);
 }
コード例 #6
0
 /// <summary>
 /// </summary>
 /// <param name="request">
 /// </param>
 /// <param name="onMessageArgs">
 /// </param>
 private void ClientMessage(HandleClientRequest request, OnMessageArgs onMessageArgs)
 {
     this.MessageReceived(request, onMessageArgs);
 }
コード例 #7
0
 /// <summary>
 /// </summary>
 /// <param name="request">
 /// </param>
 /// <param name="onMessageArgs">
 /// </param>
 private void ClientMessage(object request, OnMessageArgs onMessageArgs)
 {
     this.MessageReceived(request, onMessageArgs);
 }
コード例 #8
0
        /// <summary>
        /// Handler
        /// </summary>
        /// <param name="s">
        /// </param>
        /// <param name="a">
        /// </param>
        private void ISCClient_OnMessage(object s, OnMessageArgs a)
        {
            Console.WriteLine("[ISComm] Packet '" + a.ID + "' catched.");
            switch (a.ID)
            {
            case 0x0F:
            {
                MemoryStream stream = new MemoryStream(a.Data);
                BinaryReader reader = new BinaryReader(stream);

                uint   senderId        = reader.ReadUInt32();
                byte   msgType         = reader.ReadByte();
                short  receiversAmount = reader.ReadInt16();
                uint[] receivers       = new uint[receiversAmount];

                for (int i = 0; i < receiversAmount; i++)
                {
                    receivers[i] = reader.ReadUInt32();
                }

                string msg = reader.ReadString();
                stream.Close();
                reader.Close();

                string lookup = string.Empty;
                foreach (Client cli in this.server.Clients)
                {
                    if (cli.Character.characterId == senderId)
                    {
                        lookup = cli.Character.characterName;
                    }
                }

                byte[] namelookup = NameLookupResult.Create(senderId, lookup);

                Console.WriteLine("Got chat from ZoneEngine: " + msg);
                byte[] packet = MsgVicinity.Create(senderId, msg, msgType);

                foreach (uint sendto in receivers)
                {
                    foreach (Client cli in this.server.Clients)
                    {
                        if (cli.Character.characterId == sendto)
                        {
                            if (!cli.KnownClients.Contains(senderId))
                            {
                                cli.Send(namelookup);         // sending a namelookup ahead of the message
                                cli.KnownClients.Add(senderId);
                            }

                            cli.Send(packet);
                        }
                    }
                }
            }

            break;

            // Add characters to Team chat channel
            case 0xF0:
                PacketReader packetReader = new PacketReader(ref a.Data);

                List <uint> charIds       = new List <uint>();
                uint        numberofchars = packetReader.ReadUInt32();
                while (numberofchars > 0)
                {
                    charIds.Add(packetReader.ReadUInt32());
                }
                uint[] chars = charIds.ToArray();

                // Commented out to remove compile error.
                // Lists.ChatChannels.CreateTeamChannel(NextTeamId(),chars);


                break;
            }
        }
コード例 #9
0
        protected virtual async Task Tick(IChannel clientChannel)
        {
            if (clientChannel == null)
            {
                return;
            }

            //
            List <BaseScertMessage> responses = new List <BaseScertMessage>();
            string key = clientChannel.Id.AsLongText();

            try
            {
                //
                if (_channelDatas.TryGetValue(key, out var data))
                {
                    // Destroy
                    if (data.ShouldDestroy)
                    {
                        _forceDisconnectQueue.Enqueue(clientChannel);
                        return;
                    }

                    // Ignore
                    if (data.Ignore)
                    {
                        return;
                    }

                    // Process all messages in queue
                    while (data.RecvQueue.TryDequeue(out var message))
                    {
                        try
                        {
                            // Send to plugins
                            var onMsg = new OnMessageArgs()
                            {
                                Player  = data.ClientObject,
                                Message = message,
                                Channel = clientChannel
                            };
                            Program.Plugins.OnEvent(Plugins.PluginEvent.MEDIUS_ON_RECV, onMsg);

                            // Ignore if ignored
                            if (!onMsg.Ignore)
                            {
                                await ProcessMessage(message, clientChannel, data);
                            }
                        }
                        catch (Exception e)
                        {
                            Logger.Error(e);
                            Logger.Error($"FORCE DISCONNECTING CLIENT 1 {data} || {data.ClientObject}");
                            _           = ForceDisconnectClient(clientChannel);
                            data.Ignore = true;
                        }
                    }

                    // Send if writeable
                    if (clientChannel.IsWritable)
                    {
                        // Add send queue to responses
                        while (data.SendQueue.TryDequeue(out var message))
                        {
                            // Send to plugins
                            var onMsg = new OnMessageArgs()
                            {
                                Player  = data.ClientObject,
                                Channel = clientChannel,
                                Message = message
                            };
                            Program.Plugins.OnEvent(Plugins.PluginEvent.MEDIUS_ON_SEND, onMsg);

                            // Ignore if ignored
                            if (!onMsg.Ignore)
                            {
                                responses.Add(message);
                            }
                        }

                        if (data.ClientObject != null)
                        {
                            // Echo
                            if ((DateTime.UtcNow - data.ClientObject.UtcLastServerEchoSent).TotalSeconds > Program.Settings.ServerEchoInterval)
                            {
                                data.ClientObject.QueueServerEcho();
                            }

                            // Add client object's send queue to responses
                            while (data.ClientObject.SendMessageQueue.TryDequeue(out var message))
                            {
                                // Send to plugins
                                var onMsg = new OnMessageArgs()
                                {
                                    Player  = data.ClientObject,
                                    Message = message,
                                    Channel = clientChannel
                                };
                                Program.Plugins.OnEvent(Plugins.PluginEvent.MEDIUS_ON_SEND, onMsg);

                                // Ignore if ignored
                                if (!onMsg.Ignore)
                                {
                                    responses.Add(message);
                                }
                            }
                        }

                        //
                        if (responses.Count > 0)
                        {
                            _ = clientChannel.WriteAndFlushAsync(responses);
                        }
                    }
                }
                else
                {
                }
            }
            catch (Exception e)
            {
                Logger.Error(e);
                _forceDisconnectQueue.Enqueue(clientChannel);
                //await DisconnectClient(clientChannel);
            }
        }
コード例 #10
0
 private Task HandleAsync(OnMessageArgs message, CancellationToken stoppingToken) => commandDispatcher.DispatchAsync(message, stoppingToken);
コード例 #11
0
        /// <summary>
        /// Handler
        /// </summary>
        /// <param name="s">
        /// </param>
        /// <param name="a">
        /// </param>
        private void ISCClient_OnMessage(object s, OnMessageArgs a)
        {
            Console.WriteLine("[ISComm] Packet '" + a.ID + "' catched.");
            switch (a.ID)
            {
                case 0x0F:
                    {
                        MemoryStream stream = new MemoryStream(a.Data);
                        BinaryReader reader = new BinaryReader(stream);

                        uint senderId = reader.ReadUInt32();
                        byte msgType = reader.ReadByte();
                        short receiversAmount = reader.ReadInt16();
                        uint[] receivers = new uint[receiversAmount];

                        for (int i = 0; i < receiversAmount; i++)
                        {
                            receivers[i] = reader.ReadUInt32();
                        }

                        string msg = reader.ReadString();
                        stream.Close();
                        reader.Close();

                        string lookup = string.Empty;
                        foreach (Client cli in this.server.Clients)
                        {
                            if (cli.Character.characterId == senderId)
                            {
                                lookup = cli.Character.characterName;
                            }
                        }

                        byte[] namelookup = NameLookupResult.Create(senderId, lookup);

                        Console.WriteLine("Got chat from ZoneEngine: " + msg);
                        byte[] packet = MsgVicinity.Create(senderId, msg, msgType);

                        foreach (uint sendto in receivers)
                        {
                            foreach (Client cli in this.server.Clients)
                            {
                                if (cli.Character.characterId == sendto)
                                {
                                    if (!cli.KnownClients.Contains(senderId))
                                    {
                                        cli.Send(namelookup); // sending a namelookup ahead of the message
                                        cli.KnownClients.Add(senderId);
                                    }

                                    cli.Send(packet);
                                }
                            }
                        }
                    }

                    break;

                    // Add characters to Team chat channel
                case 0xF0:
                    PacketReader packetReader = new PacketReader(ref a.Data);

                    List<uint> charIds = new List<uint>();
                    uint numberofchars = packetReader.ReadUInt32();
                    while (numberofchars>0)
                    {
                        charIds.Add(packetReader.ReadUInt32());
                    }
                    uint[] chars = charIds.ToArray();

                    // Commented out to remove compile error.
                    // Lists.ChatChannels.CreateTeamChannel(NextTeamId(),chars);


                    break;
            }
        }
コード例 #12
0
 /// <summary>
 /// </summary>
 /// <param name="request">
 /// </param>
 /// <param name="onMessageArgs">
 /// </param>
 private void ClientMessage(HandleClientRequest request, OnMessageArgs onMessageArgs)
 {
     this.MessageReceived(request, onMessageArgs);
 }