Register for your free account! | Forgot your password?

You last visited: Today at 18:40

  • Please register to post and access all features, it's quick, easy and FREE!


Server Time & Events(Redux)

Reply
 
Old   #1
 
elite*gold: 0
Join Date: Apr 2017
Posts: 23
Received Thanks: 5
Server Time & Events(Redux)

Hello, I've been toying with the DateTime.Now.Hours within the source and I was wondering if the timing was right. Currently, if the time on my PC is 7PM, the server time is 02:00. I was trying to fix this but I have no idea what I have to tweak. Also I'm kind of curious to know if I enable something as (DateTime.Now.Hour = 19) would this start at 19:00 on my client, or when would it start at?

Also, if possible, I would like to know how to enable a current event at a certain time every day such as:

Code:
if (DateTime.Now.Hour = 19)
signup = true;
Managers.Event1.Event1Start();

if (DateTime.Now.Minute > 5)
signup = false;

if (DateTime.Now.Minute > 5 && howmanyinmap == 1)
Managers.Event1.EventEnd();
Would something like that be possible to check how many players are currently on the map and if it's past 5 minutes of the event time and you are the only player on it, end the event as soon as the last player dies?



LepEatWorld is offline  
Old 11/09/2018, 03:57   #2
 
elite*gold: 12
Join Date: Jul 2011
Posts: 7,036
Received Thanks: 3,380
C# has no way to set the timezone globally for the entire application. You would have to set each timezone for each DateTime call, but you shouldn't be doing that. Where is this server being hosted? You usually have the source code using DateTime.Now and use the system time and date. You don't try forcing another timezone unless you want to process datetimes as UTC (if you're accepting localized data from multiple regions, which you're not). If you're hosting from your own computer outside of just development, then that's another issue. If that's the case, then you might be able to run a VM? That, or set your system time.


Spirited is offline  
Old 11/09/2018, 04:20   #3
 
elite*gold: 0
Join Date: Apr 2017
Posts: 23
Received Thanks: 5
Quote:
Originally Posted by Spirited View Post
C# has no way to set the timezone globally for the entire application. You would have to set each timezone for each DateTime call, but you shouldn't be doing that. Where is this server being hosted? You usually have the source code using DateTime.Now and use the system time and date. You don't try forcing another timezone unless you want to process datetimes as UTC (if you're accepting localized data from multiple regions, which you're not). If you're hosting from your own computer outside of just development, then that's another issue. If that's the case, then you might be able to run a VM? That, or set your system time.
I'm currently toying around with the source on my own PC. I have no intention of making it public unless I feel like things would be at least 95 percent finished, which most likely wont be. The server's time and my current time don't match which is kind of annoying honestly.
LepEatWorld is offline  
Old 11/09/2018, 06:11   #4
 
elite*gold: 12
Join Date: Jul 2011
Posts: 7,036
Received Thanks: 3,380
Quote:
Originally Posted by LepEatWorld View Post
I'm currently toying around with the source on my own PC. I have no intention of making it public unless I feel like things would be at least 95 percent finished, which most likely wont be. The server's time and my current time don't match which is kind of annoying honestly.
Sorry, I'm confused. I re-read your thread, and I think I understand now? When you said "server time", you mean the server time reported by the client. You're trying to make the client's reported time the same as the actual server's system time. Is that correct? How are you constructing (packet 1033)?


Spirited is offline  
Old 11/09/2018, 19:50   #5
 
elite*gold: 0
Join Date: Apr 2017
Posts: 23
Received Thanks: 5
Quote:
Originally Posted by Spirited View Post
Sorry, I'm confused. I re-read your thread, and I think I understand now? When you said "server time", you mean the server time reported by the client. You're trying to make the client's reported time the same as the actual server's system time. Is that correct? How are you constructing (packet 1033)?
Sorry, I re-read it and it kind of confused me too at some point... but yeah that's the gist of it. Is this what you're asking for?

Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Redux.Packets.Game
{
    public unsafe struct ServerTimePacket
    {
        public DateTime Time;

        public static ServerTimePacket Create()
        {
            var packet = new ServerTimePacket
            {
                Time = DateTime.UtcNow
                    .AddHours(Constants.TIME_ADJUST_HOUR)
                    .AddMinutes(Constants.TIME_ADJUST_MIN)
                    .AddSeconds(Constants.TIME_ADJUST_SEC)
            };
            return packet;
        }

        public static implicit operator byte[](ServerTimePacket packet)
        {
            var buffer = new byte[36 + 8];
            fixed (byte* ptr = buffer)
            {
                PacketBuilder.AppendHeader(ptr, buffer.Length, Constants.MSG_DATE_TIME);
                *((int*)(ptr + 8)) = packet.Time.Year - 1900;
                *((int*)(ptr + 12)) = packet.Time.Month - 1;
                *((int*)(ptr + 16)) = packet.Time.DayOfYear;
                *((int*)(ptr + 20)) = packet.Time.Day;
                *((int*)(ptr + 24)) = packet.Time.Hour;
                *((int*)(ptr + 28)) = packet.Time.Minute;
                *((int*)(ptr + 32)) = packet.Time.Second;
            }
            return buffer;
        }
    }
}
LepEatWorld is offline  
Old 11/10/2018, 03:31   #6
 
elite*gold: 12
Join Date: Jul 2011
Posts: 7,036
Received Thanks: 3,380
Looks like a constant is setting the server's timezone offset.
Spirited is offline  
Thanks
1 User
Old 11/10/2018, 05:48   #7
 
elite*gold: 0
Join Date: Apr 2017
Posts: 23
Received Thanks: 5
Quote:
Originally Posted by Spirited View Post
Looks like a constant is setting the server's timezone offset.
Not sure if this is what I was suppose to do or if there is a better way of doing this but it works.

All I did was change:
Code:
        public const int
            TIME_ADJUST_HOUR = +2,
            TIME_ADJUST_MIN = 0,
            TIME_ADJUST_SEC = 0;
Into:
Code:
        public const int
            TIME_ADJUST_HOUR = -5,
            TIME_ADJUST_MIN = 0,
            TIME_ADJUST_SEC = 0;
I'm guessing it's because my Time Zone is UTC - 05:00

This is what the regular script looks like:
LepEatWorld is offline  
Old 11/10/2018, 18:16   #8
 
elite*gold: 0
Join Date: Jun 2010
Posts: 2,199
Received Thanks: 849
Quote:
Originally Posted by LepEatWorld View Post
Not sure if this is what I was suppose to do or if there is a better way of doing this but it works.

All I did was change:
Code:
        public const int
            TIME_ADJUST_HOUR = +2,
            TIME_ADJUST_MIN = 0,
            TIME_ADJUST_SEC = 0;
Into:
Code:
        public const int
            TIME_ADJUST_HOUR = -5,
            TIME_ADJUST_MIN = 0,
            TIME_ADJUST_SEC = 0;
I'm guessing it's because my Time Zone is UTC - 05:00

This is what the regular script looks like:
for the way this is all setup and programmed, you adjusted the time the correct way using the constants seeing ur posts a bit and v much enjoying seeing that you're trying and always asking "if there's a better way"


_DreadNought_ is offline  
Reply



« New NPC(Old Client) | Client Sided Question »

Similar Threads
[Selling] Saints Row 4, Metro Redux, Metro Last Light Redux Keys
12/14/2014 - Steam Trading - 1 Replies
---
[Buying] Metro 2033 Redux, Metro LL Redux, Fallout NV, Fallout 3, S.T.A.L.K.E.R: SoC
12/07/2014 - elite*gold Trading - 4 Replies
Suche diese Spiele für e*g (Steam).



All times are GMT +1. The time now is 18:40.


Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Abuse
Copyright ©2018 elitepvpers All Rights Reserved.