Thread: Jolt Environment: RuneScape Emulator - RS2E

Page 3 of 11 FirstFirst 12345 ... LastLast
Results 21 to 30 of 103
  1. #21  
    uber haxur
    Guest
    I might look into this, how different is C# from Java?
    Reply With Quote  
     

  2. #22  
    Registered Member

    Join Date
    Aug 2008
    Age
    28
    Posts
    774
    Thanks given
    97
    Thanks received
    131
    Rep Power
    328
    Quote Originally Posted by uber haxur View Post
    I might look into this, how different is C# from Java?
    C# / JAVA / C / C++ are similar in some ways, but the default functions / library's differ. Doesn't matter much though, if you know any object oriented programming language this should be rather easy to learn

    [Only registered and activated users can see links. ]
    Reply With Quote  
     

  3. #23  
    Registered Member

    Join Date
    Aug 2008
    Age
    28
    Posts
    774
    Thanks given
    97
    Thanks received
    131
    Rep Power
    328
    Haven't done much all week, but this is what i have done today

    - Sends update keys the client if needed
    - Partial login server (only up to check for player in database)



    The logs in gray are debug logs, they will be removed after i'm done with login

    LoginWorker.cs (Thread running the process):
    Code:
    /* ######################################## *\
     * ### Copyright (C) 2009 AJ Ravindiran ### *
    \* ######################################## */
    using System;
    using System.Threading;
    
    using AJRavindiran.Jolt.RuneScape.Models.Characters;
    
    namespace AJRavindiran.Jolt.RuneScape.Workers
    {
        /// <summary>
        /// Represents a worker.
        /// </summary>
        public class LoginWorker
        {
            #region Fields
            private Thread loginWorkerThread;
            #endregion Fields
    
            #region Constructors
            public LoginWorker()
            {
                Jolt.GetLog().WriteInfo("Constructing login worker...");
    
                // Initialize the worker thread, set the normal priority, and start it.
                this.loginWorkerThread = new Thread(new ThreadStart(Run));
                this.loginWorkerThread.Priority = ThreadPriority.Normal;
                this.loginWorkerThread.Start();
            }
            #endregion Constructors
    
            #region Destructors
            #endregion Destructors
    
            #region Methods
            /// <summary>
            /// A thread which runs the login server processor every second.
            /// </summary>
            private void Run()
            {
                while (true)
                {
                    Character[] queuedCharactersArray = new Character[
                        RuneScape.GetLoginServer().GetQueuedCharacters().Count];
                    RuneScape.GetLoginServer().GetQueuedCharacters().CopyTo(queuedCharactersArray);
    
                    foreach (Character c in queuedCharactersArray)
                    {
                        if (c.Online)
                            continue;
    
                        RuneScape.GetLoginServer().Process(c);
    
                        if (c.LoginStage == -1 || (Utilities.TimeUtilities.GetCurrentMilliseconds() - c.LoginTimeout) >= 15000)
                        {
                            RuneScape.GetLoginServer().GetQueuedCharacters().Remove(c);
    
                            if (!c.Online)
                            {
                                RuneScape.GetCharacterManager().UnRegister(c);
                            }
                        }
                    }
    
                    try
                    {
                        Thread.Sleep(100);
                    } 
                    catch (Exception ex) 
                    { 
                        Jolt.GetLog().WriteException(ex); 
                    }
                }
            }
            #endregion Methods
        }
    }
    LoginServer.cs:
    Code:
    /* ######################################## *\
     * ### Copyright (C) 2009 AJ Ravindiran ### *
    \* ######################################## */
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    using AJRavindiran.Jolt.RuneScape.Models.Characters;
    
    namespace AJRavindiran.Jolt.RuneScape.Network.Login
    {
        /// <summary>
        /// Represents a login server.
        /// </summary>
        public class LoginServer
        {
            #region Fields
            /// <summary>
            /// Container for all queued characters.
            /// </summary>
            private HashSet<Character> queuedCharacters;
    
            private LoginUpdateServer loginUpdateServer;
            private LoginStreamBuffer loginStreamBuffer;
            #endregion Fields
    
            #region Constructors
            /// <summary>
            /// Constructs a new login server class.
            /// </summary>
            public LoginServer()
            {
                Jolt.GetLog().WriteInfo("Constructing login server...");
                // Initialize the container.
                this.queuedCharacters = new HashSet<Character>();
    
                // Initialize sister clases.
                this.loginUpdateServer = new LoginUpdateServer();
                this.loginStreamBuffer = new LoginStreamBuffer();
            }
            #endregion Constructors
    
            #region Methods
            /// <summary>
            /// Attempts to login all the users queued in the container.
            /// </summary>
            /// <param name="character"></param>
            public void Process(Character character)
            {
                try
                {
                    character.ServerSessionKey = ((long)(new Random().NextDouble() * 99999999D) << 32) + (long)(new Random().NextDouble() * 99999999D);
                    character.ClientSessionKey = 0;
                    LoginCodesEnumeration returnCode = LoginCodesEnumeration.LoginOK;
    
                    if (character.LoginStage < -1)
                    {
                        this.loginUpdateServer.SendUpdateKeys(character);
                        Jolt.GetLog().WriteDebug("Sending update keys (login stage -1)");
                    }
                    else if (character.LoginStage == 0)
                    {
                        Jolt.GetLog().WriteDebug("Login stage == 0");
                        try
                        {
                            if (!this.loginStreamBuffer.FillStream(character, 2))
                            {
                                Jolt.GetLog().WriteDebug("FillStream(2) failed.");
                                return;
                            }
                        }
                        catch (Exception) { return; }
    
                        byte connectionType = character.GetStreamReader().ReadByte();
    
                        Jolt.GetLog().WriteDebug("conection type: " + connectionType.ToString());
                        if (connectionType == 15)
                        {
                            this.loginUpdateServer.SendUpdateKeys(character);
                            character.LoginStage = -5;
                            return;
                        }
    
                        if (connectionType != 14)
                        {
                            character.LoginStage = -1;
                            return;
                        }
    
                        byte longPlayerName = character.GetStreamReader().ReadByte();
                        Jolt.GetLog().WriteDebug("Long player name: " + longPlayerName.ToString());
                        character.GetStreamWriter().WriteByte(0);
                        character.GetStreamWriter().WriteLong(character.ServerSessionKey);
                        this.loginStreamBuffer.DirectFlushStream(character);
                        character.LoginStage++;
                    }
                    else if (character.LoginStage == 1)
                    {
                        Jolt.GetLog().WriteDebug("login stage == 1");
                        try
                        {
                            if (!this.loginStreamBuffer.FillStream(character, 3))
                            {
                                Jolt.GetLog().WriteDebug("Fillstream(3) failed.");
                                return;
                            }
                        }
                        catch (Exception) { return; }
    
                        int loginType = character.GetStreamReader().ReadByte();
                        Jolt.GetLog().WriteDebug("login type: " + loginType.ToString());
                        if (loginType != 16 && loginType != 18 && loginType != 14)
                        {
                            character.LoginStage = -1;
                            return;
                        }
    
                        character.LoginStage++;
                    }
                    else if (character.LoginStage == 2)
                    {
                        Jolt.GetLog().WriteDebug("login stage == 2");
                        int loginPacketSize = character.GetStreamReader().ReadUShort();
                        Jolt.GetLog().WriteDebug("login packet size: " + loginPacketSize.ToString());
                        int loginEncryptPacketSize = loginPacketSize - (36 + 1 + 1 + 2);
                        Jolt.GetLog().WriteDebug("login encrypted size: " + loginEncryptPacketSize.ToString());
                        if (loginEncryptPacketSize <= 0)
                        {
                            character.LoginStage = -1;
                            return;
                        }
    
                        try
                        {
                            if (!this.loginStreamBuffer.FillStream(character, loginPacketSize))
                            {
                                Jolt.GetLog().WriteDebug("fillstream(packetsize) failed.");
                                return;
                            }
                        }
                        catch (Exception ex) 
                        {
                            Jolt.GetLog().WriteException(ex);
                            return;
                        }
    
                        int clientVersion = character.GetStreamReader().ReadInt();
                        Jolt.GetLog().WriteDebug("client version: " + clientVersion.ToString());
                        if (clientVersion != 508)
                        {
                            character.LoginStage = -1;
                            return;
                        }
    
                        character.GetStreamReader().ReadByte();
                        character.GetStreamReader().ReadUShort();
                        character.GetStreamReader().ReadUShort();
                        for (int i = 0; i < 24; i++)
                        {
                            int cacheIndex = character.GetStreamReader().ReadByte();
                        }
    
                        string junk = character.GetStreamReader().ReadString();
                        for (int i = 0; i < 29; i++)
                        {
                            int junk2 = character.GetStreamReader().ReadInt();
                        }
    
                        loginEncryptPacketSize--;
                        byte junk29 = character.GetStreamReader().ReadByte();
                        byte encryption = character.GetStreamReader().ReadByte();
                        if (encryption != 10 & encryption != 64)
                        {
                            character.LoginStage = -1;
                            return;
                        }
    
                        character.ClientSessionKey = character.GetStreamReader().ReadLong();
                        character.ServerSessionKey = character.GetStreamReader().ReadLong();
                        character.Username = Utilities.MathUtilities.LongToString(character.GetStreamReader().ReadLong()).ToLower().Trim();
                        if (character.Username == null)
                        {
                            character.LoginStage = -1;
                            character.Username = "null";
                            return;
                        }
                        Jolt.GetLog().WriteDebug("username: " + character.Username);
    
                        for (int i = 0; i < character.Username.Length; i++)
                        {
                            char c = character.Username[i];
                            if (!char.IsLetterOrDigit(c) && !char.IsWhiteSpace(c))
                            {
                                character.LoginStage = -1;
                                character.Username = "null";
                                return;
                            }
                        }
    
                        if (RuneScape.GetCharacterManager().IsOnline(character))
                            returnCode = LoginCodesEnumeration.AlreadyOnline;
                        if (RuneScape.GetOffenceManager().GetBans().IsBanned(character))
                            returnCode = LoginCodesEnumeration.AccountDisabled;
                        if (RuneScape.GetOffenceManager().GetIPBans().IsBanned(character))
                            returnCode = LoginCodesEnumeration.AccountDisabled;
                        if (RuneScape.GetOffenceManager().GetMutes().IsMuted(character))
                            character.Muted = true;
    
                        string password = character.GetStreamReader().ReadString();
                        if (password == null)
                        {
                            character.LoginStage = -1;
                            return;
                        }
                        bool isValid = RuneScape.GetCharacterManager().GetLoader().Execute(character);
                        try
                        {
                            password = Utilities.Security.Cryptography.MD5[password];
                        }
                        catch (Exception ex)
                        {
                            Jolt.GetLog().WriteException(ex);
                            password = "null";
                        }
    
                        if (password != null && character.Password != null && character.Password != "null" && !character.Password.Equals(password) || !isValid)
                            returnCode = LoginCodesEnumeration.InvalidPassword;
    
                        // Set player online database.
    
                        character.GetStreamWriter().WriteByte((int)returnCode);
                        character.GetStreamWriter().WriteByte(character.Rights);
                        character.GetStreamWriter().WriteByte(0);
                        character.GetStreamWriter().WriteByte(0);
                        character.GetStreamWriter().WriteByte(0);
                        character.GetStreamWriter().WriteByte(1);
                        character.GetStreamWriter().WriteByte(0);
                        character.GetStreamWriter().WriteByte(character.ConnectionID);
                        character.GetStreamWriter().WriteByte(0);
                        this.loginStreamBuffer.DirectFlushStream(character);
                    }
                    
                }
                catch (Login.Exceptions.InvalidLoginException ile)
                {
                    throw ile;
                }
            }
    
            /// <summary>
            /// Add a character to the login queue.
            /// </summary>
            /// <param name="character">The player to queue in for login.</param>
            public void AddToLoginQueue(Character character)
            {
                queuedCharacters.Add(character);
            }
    
            /// <summary>
            /// Remove a player from the login queue.
            /// </summary>
            /// <param name="character">The player to queue out from the login.</param>
            public void RemoveFromLoginQueue(Character character)
            {
                queuedCharacters.Remove(character);
            }
    
            /// <summary>
            /// Accessor for the queued players hashset.
            /// </summary>
            /// <returns></returns>
            public HashSet<Character> GetQueuedCharacters()
            {
                return this.queuedCharacters;
            }
    
            /// <summary>
            /// Accessor for the update server class.
            /// </summary>
            /// <returns></returns>
            public LoginUpdateServer GetUpdateServer()
            {
                return this.loginUpdateServer;
            }
    
            /// <summary>
            /// Accessor for the stream buffer class.
            /// </summary>
            /// <returns></returns>
            public LoginStreamBuffer GetStreamBuffer()
            {
                return this.loginStreamBuffer;
            }
            #endregion
        }
    }
    LoginCodeEnumeration.cs:
    Code:
    /* ######################################## *\
     * ### Copyright (C) 2009 AJ Ravindiran ### *
    \* ######################################## */
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace AJRavindiran.Jolt.RuneScape.Network.Login
    {
        /// <summary>
        /// Represents the login return codes.
        /// </summary>
        public enum LoginCodesEnumeration : byte
        {
            LoginOK = 2,
            InvalidPassword = 3,
            AccountDisabled = 4,
            AlreadyOnline = 5,
            WorldFull = 6,
            TryAgain = 11
        }
    }
    LoginStreamBuffer.cs:
    Code:
    /* ######################################## *\
     * ### Copyright (C) 2009 AJ Ravindiran ### *
    \* ######################################## */
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace AJRavindiran.Jolt.RuneScape.Network.Login
    {
        /// <summary>
        /// Represents a login stream buffer.
        /// </summary>
        public class LoginStreamBuffer
        {
            #region Methods
            /// <summary>
            /// Check and read any incoming bytes.
            /// </summary>
            public bool FillStream(Models.Characters.Character character, int forceRead)
            {
                try
                {
                    if (forceRead >= 500)
                        return false;
                    if (character.GetPlayerSocket().Availible < forceRead)
                        return false;
    
                    character.GetStreamReader().ReadOffset = 0;
                    character.GetPlayerSocket().Read(forceRead);
                    return true;
                }
                catch (StreamException se)
                {
                    Jolt.GetLog().WriteException(se);
                    throw se;
                }
            }
    
            /// <summary>
            /// Send the bytes in the stream's outBuffer directly to the client.
            /// </summary>
            public void DirectFlushStream(Models.Characters.Character character)
            {
                try
                {
                    character.GetPlayerSocket().Write(
                        character.GetStreamWriter().OutBuffer, 0, 
                        character.GetStreamWriter().WriteOffset);
                    character.GetStreamWriter().WriteOffset = 0;
                }
                catch (StreamException se)
                {
                    Jolt.GetLog().WriteException(se);
                    throw se;
                }
            }
            #endregion Methods
        }
    }
    LoginUpdateServer.cs:
    Code:
    /* ######################################## *\
     * ### Copyright (C) 2009 AJ Ravindiran ### *
    \* ######################################## */
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace AJRavindiran.Jolt.RuneScape.Network.Login
    {
        /// <summary>
        /// Represents a login update server.
        /// </summary>
        public class LoginUpdateServer
        {
            #region Fields
            /// <summary>
            /// The update keys needed to update the r508 client.
            /// </summary>
            private int[] updateKeys =
            {            
                0xff, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0xd8, 
                0x84, 0xa1, 0xa1, 0x2b, 0x00, 0x00, 0x00, 0xba, 
                0x58, 0x64, 0xe8, 0x14, 0x00, 0x00, 0x00, 0x7b, 
                0xcc, 0xa0, 0x7e, 0x23, 0x00, 0x00, 0x00, 0x48, 
                0x20, 0x0e, 0xe3, 0x6e, 0x00, 0x00, 0x01, 0x88, 
                0xec, 0x0d, 0x58, 0xed, 0x00, 0x00, 0x00, 0x71, 
                0xb9, 0x4c, 0xc0, 0x50, 0x00, 0x00, 0x01, 0x8b, 
                0x5b, 0x61, 0x79, 0x20, 0x00, 0x00, 0x00, 0x0c, 
                0x0c, 0x69, 0xb1, 0xc8, 0x00, 0x00, 0x02, 0x31, 
                0xc8, 0x56, 0x67, 0x52, 0x00, 0x00, 0x00, 0x69, 
                0x78, 0x17, 0x7b, 0xe2, 0x00, 0x00, 0x00, 0xc3, 
                0x29, 0x76, 0x27, 0x6a, 0x00, 0x00, 0x00, 0x05, 
                0x44, 0xe7, 0x75, 0xcb, 0x00, 0x00, 0x00, 0x08, 
                0x7d, 0x21, 0x80, 0xd5, 0x00, 0x00, 0x01, 0x58, 
                0xeb, 0x7d, 0x49, 0x8e, 0x00, 0x00, 0x00, 0x0c, 
                0xf4, 0xdf, 0xd6, 0x4d, 0x00, 0x00, 0x00, 0x18, 
                0xec, 0x33, 0x31, 0x7e, 0x00, 0x00, 0x00, 0x01, 
                0xf7, 0x7a, 0x09, 0xe3, 0x00, 0x00, 0x00, 0xd7, 
                0xe6, 0xa7, 0xa5, 0x18, 0x00, 0x00, 0x00, 0x45, 
                0xb5, 0x0a, 0xe0, 0x64, 0x00, 0x00, 0x00, 0x75, 
                0xba, 0xf2, 0xa2, 0xb9, 0x00, 0x00, 0x00, 0x5f, 
                0x31, 0xff, 0xfd, 0x16, 0x00, 0x00, 0x01, 0x48, 
                0x03, 0xf5, 0x55, 0xab, 0x00, 0x00, 0x00, 0x1e, 
                0x85, 0x03, 0x5e, 0xa7, 0x00, 0x00, 0x00, 0x23, 
                0x4e, 0x81, 0xae, 0x7d, 0x00, 0x00, 0x00, 0x18, 
                0x67, 0x07, 0x33, 0xe3, 0x00, 0x00, 0x00, 0x14, 
                0xab, 0x81, 0x05, 0xac, 0x00, 0x00, 0x00, 0x03, 
                0x24, 0x75, 0x85, 0x14, 0x00, 0x00, 0x00, 0x36
            };
            #endregion Fields
    
            #region Methods
            /// <summary>
            /// If the connection is the client's update server than send the keys.
            /// </summary>
            public void SendUpdateKeys(Models.Characters.Character character)
            {
                try
                {
                    if (character.LoginStage == 0)
                    {
                        if (!RuneScape.GetLoginServer().GetStreamBuffer().FillStream(character, 3))
                            return;
                        character.GetStreamWriter().WriteByte(0);
                        RuneScape.GetLoginServer().GetStreamBuffer().DirectFlushStream(character);
                    }
                    else if (character.LoginStage == -5)
                    {
                        if (!RuneScape.GetLoginServer().GetStreamBuffer().FillStream(character, 8))
                            return;
                        for (int i = 0; i < updateKeys.Length; i++)
                            character.GetStreamWriter().WriteByte(updateKeys[i]);
                        RuneScape.GetLoginServer().GetStreamBuffer().DirectFlushStream(character);
                        character.LoginStage = -1;
                    }
                }
                catch (Login.Exceptions.UpdateServerException use)
                {
                    Jolt.GetLog().WriteException(use);
                    throw use;
                }
            }
            #endregion Methods
        }
    }

    [Only registered and activated users can see links. ]
    Reply With Quote  
     

  4. #24  
    Tom
    Tom is offline
    Registered Member
    Tom's Avatar
    Join Date
    Jul 2006
    Age
    27
    Posts
    1,148
    Thanks given
    8
    Thanks received
    86
    Rep Power
    902
    C# sucks dick
    uh
    Reply With Quote  
     

  5. #25  
    Registered Member

    Join Date
    Aug 2008
    Age
    28
    Posts
    774
    Thanks given
    97
    Thanks received
    131
    Rep Power
    328
    Quote Originally Posted by Tom View Post
    C# sucks dick
    JAVA sucks dick
    Tom's mother sucks dicks aswell

    Immature right?


    Idiots like you should stay out of my thread. If you don't like the language, why are you here to say so? Complain else where.
    Most likely you are saying this cause you don't know C# at all.

    [Only registered and activated users can see links. ]
    Reply With Quote  
     

  6. #26  
    I_-_I
    Guest
    Quote Originally Posted by TheAJ View Post
    JAVA sucks dick
    lold, nope
    Reply With Quote  
     

  7. #27  
    Java/C++ Programmer

    Join Date
    Jun 2008
    Age
    25
    Posts
    1,378
    Thanks given
    203
    Thanks received
    387
    Rep Power
    815
    i dont like how c# code looks
    Reply With Quote  
     

  8. #28  
    Tom
    Tom is offline
    Registered Member
    Tom's Avatar
    Join Date
    Jul 2006
    Age
    27
    Posts
    1,148
    Thanks given
    8
    Thanks received
    86
    Rep Power
    902
    Quote Originally Posted by TheAJ View Post
    JAVA sucks dick
    Tom's mother sucks dicks aswell

    Immature right?


    Idiots like you should stay out of my thread. If you don't like the language, why are you here to say so? Complain else where.
    Most likely you are saying this cause you don't know C# at all.
    I'm here to say so so that you realize its a waste of time to try and write a server using it because no one will use it, no one will appreciate it, and it will get nowhere. It would seem that you believe your time is worthless however.

    Also, What does my not knowing the language inside out have to do with me not liking the language? Would I learn a language I don't like? By your logic, no-one can decide whether they like something until they've studied it through and through. You're intelligent.
    uh
    Reply With Quote  
     

  9. #29  
    Registered Member

    Join Date
    Aug 2008
    Age
    28
    Posts
    774
    Thanks given
    97
    Thanks received
    131
    Rep Power
    328
    Quote Originally Posted by Tom View Post
    I'm here to say so so that you realize its a waste of time to try and write a server using it because no one will use it, no one will appreciate it, and it will get nowhere. It would seem that you believe your time is worthless however.

    Also, What does my not knowing the language inside out have to do with me not liking the language? Would I learn a language I don't like? By your logic, no-one can decide whether they like something until they've studied it through and through. You're intelligent.
    This is for my knowledge, I'm simply posting a developement thread incase others want to try another language, instead of dumbasses like you who think JAVA is the only language you can program in.

    I doubt you know JAVA at all outside of runescape. You ahve probably only adopted to runescape frameworks, and what not, and talk like it's your profession. I can bet i know more knowledge in JAVA than you. You clearly do not stand as a veteran for programming.

    Also, when did the logical "If i hate it, everyone else does" come in?
    You hate C#, so what? You probably haven't looked in it's background nor have tried it.

    [Only registered and activated users can see links. ]
    Reply With Quote  
     

  10. #30  
    Registered Member

    Join Date
    Aug 2008
    Age
    28
    Posts
    774
    Thanks given
    97
    Thanks received
    131
    Rep Power
    328
    Quote Originally Posted by Dux.. View Post
    Sorry, but Tom DOES in fact know more than you. And this is in a neutral point of view. So don't get all bottled up inside of your feeling and find the need to defend yourself as its a fact.
    Yes buddy, you should know it's a fact right?

    Anyways, please back to topic. If you still want to banter, please go ahead and create a new thread

    [Only registered and activated users can see links. ]
    Reply With Quote  
     

Page 3 of 11 FirstFirst 12345 ... LastLast

Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •