コード例 #1
0
        private static void ReadPrivateMessage(BinaryReader reader, Socket connection)
        {
            string targetPlayerName = reader.ReadMmoString();
            string playerMessage    = reader.ReadMmoString();

            ConQue.Enqueue(() => ProcessPrivateMessage(playerMessage, targetPlayerName, connection));
        }
コード例 #2
0
ファイル: Logic.cs プロジェクト: Amaratsu/COOServer
        public static async Task UpdateClansAsync()
        {
            Console.WriteLine("Requesting clans from database.");
            string response = await SendRequestAsync("ClanCharacters", "");

            Console.WriteLine("Received clans.");
            ClansOutput result = JsonSerializer.Deserialize <ClansOutput>(response);

            ConQue.Enqueue(() => UpdateClansWithInfo(result));
        }
コード例 #3
0
ファイル: Logic.cs プロジェクト: Amaratsu/COOServer
        public static async Task SendClanKickAsync(Player targetPlayer)
        {
            string response = await SendRequestAsync("DeleteCharacterFromClan",
                                                     "{\"CharacterId\":\"" + targetPlayer.Id + "\"}"
                                                     );

            if (response.Contains("OK"))
            {
                ConQue.Enqueue(StartClansUpdate);
            }
        }
コード例 #4
0
ファイル: Logic.cs プロジェクト: Amaratsu/COOServer
        public static async Task SendCreateClanAsync(Player thisPlayer, string clanName)
        {
            string response = await SendRequestAsync("CreateClan",
                                                     "{\"CharacterName\":\"" + thisPlayer.Name + "\"," +
                                                     "\"ClanName\":\"" + clanName + "\"}"
                                                     );

            if (response.Contains("OK"))
            {
                ConQue.Enqueue(StartClansUpdate);
            }
        }
コード例 #5
0
ファイル: Logic.cs プロジェクト: Amaratsu/COOServer
        public static void CreatePendingInvite(Player invitedPlayer, Player invitingParty, bool bClanInvite)
        {
            invitedPlayer.PendingInvite        = invitingParty;
            invitedPlayer.HasPendingClanInvite = bClanInvite;
            double delay   = 20000.0; // 20 seconds, 1000 ms is one second
            var    myTimer = new System.Timers.Timer(delay);

            myTimer.Elapsed  += (sender, args) => ConQue.Enqueue(() => ClearPendingInvite(invitedPlayer));
            myTimer.AutoReset = false; // fire only once
            myTimer.Enabled   = true;
            PendingInvites.Add(invitedPlayer, myTimer);
        }
コード例 #6
0
ファイル: Logic.cs プロジェクト: Amaratsu/COOServer
 public static void CreatePendingKick(Player playerToKick)
 {
     if (!PendingKicks.ContainsKey(playerToKick.Name))
     {
         double delay   = 30000.0;
         var    myTimer = new System.Timers.Timer(delay);
         myTimer.Elapsed  += (sender, args) => ConQue.Enqueue(() => ClearPendingKick(playerToKick));
         myTimer.AutoReset = false; // fire only once
         myTimer.Enabled   = true;
         PendingKicks.Add(playerToKick.Name, myTimer);
     }
 }
コード例 #7
0
ファイル: Main.cs プロジェクト: Amaratsu/COOServer
        static string Hostname = "http://localhost:55326/";                                     //url is loaded from hostname.ini

        public static void Start()
        {
            //using (var myFile = new StreamReader("hostname.ini"))
            //{
            //    Hostname = myFile.ReadToEnd(); // Read the file as one string
            //}
            Console.WriteLine("url: " + Hostname);
            ConQue.Enqueue(StartClansUpdate); // download clans from DB on first launch

            _ = ProcessorLoop();              // launch the loop that will 'tick' once every 8ms. It will process Actions on the concurrent queue.

            StartListening();                 // Each connection will run asynchronously.
        }
コード例 #8
0
ファイル: Logic.cs プロジェクト: Amaratsu/COOServer
        public static async Task SendDisbandClanAsync(Player thisPlayer)
        {
            string response = await SendRequestAsync("DisbandClan",
                                                     "{\"CharacterId\":\"" + thisPlayer.Id + "\"}"
                                                     );

            if (response.Contains("OK"))
            {
                Console.WriteLine($"Clan disbanded by: {thisPlayer.Name}");
                ConQue.Enqueue(StartClansUpdate);
            }
            else
            {
                Console.WriteLine($"Clan disband by {thisPlayer.Name} failed. Response: {response}");
            }
        }
コード例 #9
0
ファイル: Logic.cs プロジェクト: Amaratsu/COOServer
        public static async Task SendPlayerJoinedClanAsync(Player thisPlayer, Player invitingPlayer)
        {
            string response = await SendRequestAsync("AddCharacterToClan",
                                                     "{\"CharacterName\":\"" + thisPlayer.Name + "\"," +
                                                     "\"ClanId\":\"" + invitingPlayer.ClanId + "\"}"
                                                     );

            if (response.Contains("OK"))
            {
                Console.WriteLine($"Database processed clan invite for player: {thisPlayer.Name}");
                ConQue.Enqueue(StartClansUpdate);
            }
            else
            {
                Console.WriteLine($"Clan invite for {thisPlayer.Name} failed. Response: {response}");
            }
        }
コード例 #10
0
        private static void ReadClanKick(BinaryReader reader, Socket connection)
        {
            string targetPlayerName = reader.ReadMmoString();

            ConQue.Enqueue(() => ProcessClanKick(targetPlayerName, connection));
        }
コード例 #11
0
 private static void ReadGroupLeave(Socket connection)
 {
     ConQue.Enqueue(() => ProcessGroupLeave(connection));
 }
コード例 #12
0
 private static void ReadClanDisband(Socket connection)
 {
     ConQue.Enqueue(() => ProcessClanDisband(connection));
 }
コード例 #13
0
        private static void ReadClanInvite(BinaryReader reader, Socket connection)
        {
            string invitedPlayer = reader.ReadMmoString();

            ConQue.Enqueue(() => ProcessClanInvite(invitedPlayer, connection));
        }
コード例 #14
0
        private static void ReadClanCreate(BinaryReader reader, Socket connection)
        {
            string clanName = reader.ReadMmoString();

            ConQue.Enqueue(() => ProcessClanCreate(clanName, connection));
        }
コード例 #15
0
 private static void ReadDeclineInvite(Socket connection)
 {
     ConQue.Enqueue(() => ProcessDeclineInvite(connection));
 }
コード例 #16
0
 private static void ReadAcceptInvite(Socket connection)
 {
     ConQue.Enqueue(() => ProcessAcceptInvite(connection));
 }
コード例 #17
0
        public static void ReadLogin(BinaryReader reader, Socket connection)
        {
            string charName = reader.ReadMmoString();

            ConQue.Enqueue(() => ProcessLogin(charName, connection));
        }
コード例 #18
0
ファイル: Main.cs プロジェクト: Amaratsu/COOServer
        public static void ReadMessage(IAsyncResult ar)
        {
            // Retrieve the state object and the handler socket from the asynchronous state object.
            StateObject state      = (StateObject)ar.AsyncState;
            Socket      connection = state.WorkSocket;

            if (!connection.Connected)
            {
                return;
            }
            try
            {
                int bytesRead = connection.EndReceive(ar);

                // disconnect happened
                if (bytesRead == 0)
                {
                    ConQue.Enqueue(() => KickConnection(connection));
                    connection.Close();
                    return;
                }

                //Read the first byte to determine the type of "command" we received and switch on it
                Stream       stream = new MemoryStream(state.Buffer);
                BinaryReader reader = new BinaryReader(stream);
                while (reader.PeekChar() > 0) // -1 is "end of stream", "0" is "undefined"
                {
                    Command cmd = (Command)reader.ReadByte();
                    switch (cmd)
                    {
                    case Command.Login: ReadLogin(reader, connection); break;

                    //case Command.Logout: break; // no need, a dropped connection is caught elsewhere
                    case Command.GeneralMessage: ReadGeneralMessage(reader, connection); break;

                    case Command.PrivateMessage: ReadPrivateMessage(reader, connection); break;

                    case Command.GroupMessage: ReadGroupMessage(reader, connection); break;

                    case Command.ClanMessage: ReadClanMessage(reader, connection); break;

                    case Command.GroupInvite: ReadGroupInvite(reader, connection); break;

                    case Command.AcceptInvite: ReadAcceptInvite(connection); break;     // accept group invite or clan invite

                    case Command.DeclineInvite: ReadDeclineInvite(connection); break;

                    case Command.ClanCreate: ReadClanCreate(reader, connection); break;

                    case Command.ClanInvite: ReadClanInvite(reader, connection); break;

                    case Command.ClanDisband: ReadClanDisband(connection); break;

                    case Command.ClanLeave: ReadClanLeave(connection); break;

                    case Command.GroupLeave: ReadGroupLeave(connection); break;

                    case Command.ClanKick: ReadClanKick(reader, connection); break;

                    case Command.GroupKick: ReadGroupKick(reader, connection); break;
                    }
                }

                // listen again:
                state.ResetBuffer();
                connection.BeginReceive(state.Buffer, 0, StateObject.BufferSize, 0, ReadMessage, state);
            }
            catch (SocketException socketException)
            {
                //WSAECONNRESET, the other side closed impolitely
                if (socketException.ErrorCode == 10054 ||
                    ((socketException.ErrorCode != 10004) &&
                     (socketException.ErrorCode != 10053)))
                {
                    Console.WriteLine("remote client disconnected");
                }
                else
                {
                    Console.WriteLine(socketException.Message);
                }
                ConQue.Enqueue(() => KickPlayer(connection));
                connection.Close(); //@TODO: is this necessary?
            }
            catch (EndOfStreamException)
            {
                Console.WriteLine("EndOfStreamException exception");
                // listen again:
                state.ResetBuffer();
                connection.BeginReceive(state.Buffer, 0, StateObject.BufferSize, 0, ReadMessage, state);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message + "\n" + e.StackTrace);
                ConQue.Enqueue(() => KickPlayer(connection));
                connection.Close();//@TODO: check if this is necessary
            }
        }
コード例 #19
0
        private static void ReadClanMessage(BinaryReader reader, Socket connection)
        {
            string playerMessage = reader.ReadMmoString();

            ConQue.Enqueue(() => ProcessClanMessage(playerMessage, connection));
        }