Last Login Time

07/15/2012 16:49 diedwarrior#1
Hey, after A LOT of trial and error, I couldn't really figure how its used to send the time probably, I tried to control the time sent many times, I figured out there's 4 bytes that controls the time sent, i tried them as ushorts and as a uint, but still they're pretty fucked, so i made a command to test em as 4 individual bytes, but yeah, still no luck, so anyone got any information about this ?
[Only registered and activated users can see links. Click Here To Register...]
07/15/2012 19:33 -impulse-#2
Yes. You send seconds as a whole (the whole date (current year - 1970) in seconds)
07/15/2012 22:44 diedwarrior#4
Thanks a lot, appreciate it.
#request close.
07/15/2012 22:45 romeoromeo#5
Quote:
Originally Posted by -impulse- View Post
Yes. You send seconds as a whole (the whole date (current year - 1970) in seconds)
That means its ulong or 8 bytes ...... eh ?
07/15/2012 22:52 Zeroxelli#6
It's anywhere from 4 bytes to 8 bytes, usually 8, depending on the format. If it's seconds and not milliseconds, a UInt32 might suffice.
07/15/2012 23:09 diedwarrior#7
No, a uint.
It's using seconds, not ms so a uint is enough.
07/15/2012 23:19 Zeroxelli#8
Yeah, that's what UInt32 is lol. UInt16 = uShort, UInt64 = uLong
07/15/2012 23:38 diedwarrior#9
-.-, no shit, I already know don't worry xD, didn't see your comment that's why i posted mine.
07/15/2012 23:46 Zeroxelli#10
Ahh my bad :p Assumed you might have been confused like I was going from C[++] to C#. I was used to having to do
Code:
typedef unsigned short int ushort;
and such.
07/15/2012 23:57 diedwarrior#11
Ah lol, you seem to be an experienced coder xD.
Anyways here's a quick code to convert in case some people are still finding it hard.
Code:
   public  static double Convert(DateTime date)
        {
            DateTime originaldate = new DateTime(1970, 1, 1, 0, 0, 0, 0);
            TimeSpan a7a = date - originaldate;
            Console.WriteLine(a7a.TotalSeconds);
            return Math.Floor(a7a.TotalSeconds);
          
        }
07/16/2012 00:07 Zeroxelli#12
I've posted this many times before, but here's another way of doing it :)

Quote:
Originally Posted by Zeroxelli View Post
Also, a heads up. People tend to use Environment.TickCount to measure the distance between two points in time in their servers. This is not good practice! Though it is okay in certain circumstances where the difference in time is less than, say, 3-4 weeks, any more than that and it will wrap around to a negative number and screw up your system. I recommend that it is avoided completely, short of checking the time between things inside the server itself, such as your last jump, attack, etc. Other than that, I recommend you use something like a unix epoch timestamp. As I've posted before, use these functions I've made, or something similar:

Code:
       public static readonly DateTime Epoch = new DateTime(1970, 1, 1);

        public static long Microtime()
        {
            return Convert.ToInt64((DateTime.UtcNow - Epoch).TotalMilliseconds);
        }

        public static long MilliSecondsSince(long UTS)
        {
            return (Microtime() - UTS);
        }

        public static long SecondsSince(long UTS)
        {
            return (Microtime() - UTS) / 1000;
        }
Of course you can make a simple function to return the seconds instead, but "SecondsSince" works nice for calculating the time between now (use Microtime() to get the UTS timestamp for "Now") and the unix epoch.
07/16/2012 00:09 diedwarrior#13
Ah, That's a nice code, thanks :D.
07/16/2012 01:47 nTL3fTy#14
Code:
[DllImport("msvcrt.dll", EntryPoint = "_time32", CallingConvention = CallingConvention.Cdecl)]
public static extern uint GetUnixTime32(uint timer = 0);

[DllImport("msvcrt.dll", EntryPoint = "_time64", CallingConvention = CallingConvention.Cdecl)]
public static extern ulong GetUnixTime64(ulong timer = 0);
Simple.