Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by surfuay · Apr 13, 2019 at 04:59 PM · serverrestartoffline

variable increase based on passing time using server

Hey guys,

Need some help.

Here's what I have:

My server is set, accessing and splitting the string is all good for date and time. Here's my problem.

I am successfully saving the end time of the app as well as the new start time. I'm trying to find the difference between the two times to decide how much to reward the payer.

Here's the problem, no matter how I try the math I will always have the problem that at midnight the number will go negative. here's an example

at 12:05:59 we close, cool

at 01:05:34 we start (it actually reads 13:05:34) still good since the second number is obviously larger than the first.

The problem is if i have any time before midnight that I close the game and then open it after that

So close game at 23:59:59 then open at 08:15:59

even those roughly 8 hours has passed the equation will throw a negative instead of a positive. The problem occurs even if i incoporate the date just in different ways

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Bunny83 · Apr 13, 2019 at 05:24 PM

Well, you ignored the days that have passed completely. Since you use your custom time from your server it's not clear what you actually receive from your server so we can't suggest a fix. However you generally have to include the date as well as the time (which in computer science is generally called a DateTime value). When you include the date in your calculations the issue should go away. Actually the DateTime struct already can calculate time differences. If you have your date / time values as seperate values you can simply initialize a DateTime value with them.


Keep in mind that using an external time server is pretty pointless if you don't use https with an actual valid certificate. Otherwise it's equally simple to spoof the time you get from your server. An additional symmetric encryption and checksum would help as well, though that's up to you.

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image surfuay · Apr 13, 2019 at 05:37 PM 0
Share

well, no, i did mention that i use the date as well in the last line of my question and the problem persists regardless. but i was under the impression that using DateTime value is a localized occurence which would allow the user to simply forward their phones time for rewards.

the server does use the https there is a valid cert so it looks like i have the correct start there at least

my actual code gets this format of information from the server $$anonymous$$$$anonymous$$ - DD - YYYY / HH : $$anonymous$$$$anonymous$$ : SS as a string which i know how to parse to an int if necessary (and i've tried)

can you give me a starting point of code on how to use what i've got? I have gone to your links tho, they really helped conceptually what I'm doing wrong but I'm a bit at a loss on where to start a calc method

thanks either way this is really helpful and should get me moving further.

avatar image Bunny83 surfuay · Apr 15, 2019 at 05:05 PM 0
Share

I just read your comment. The format you use to send the date from your server is way too complicated for computer processing. Why did you choose such a format? It makes things much easier to either use a single seperation character and just split the string on that, or just use a more standardized format like json. A format like this would make much more sense:

 yyyy/$$anonymous$$$$anonymous$$/dd/HH/mm/ss

Note that i used the default C# date format string specifiers here. "$$anonymous$$$$anonymous$$" is the two digits month while "mm" are the two digit $$anonymous$$utes. Though for computer processing a format like this would be simpler

 yyyy/$$anonymous$$/d/H/m/s

as you don't need any leading zeros which could sometimes create issues. The current date/time would be

 2019/4/15/19/5/30
avatar image surfuay Bunny83 · Apr 15, 2019 at 05:22 PM 0
Share

yeah, that makes sense. I'm brand new to using a server and accessing it, but it makes sense that my starting point is too complex I'll simplify it and see if that makes further progress easier.

I'm unfamiliar with JSON, i've tried learning, any good starting tutorials for JSON?

overall your input has been super useful on getting me to some good starting points.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

105 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Unity networking tutorial? 6 Answers

Master Server Requirements? 2 Answers

Faking Dedicated Servers in Unity 1 Answer

time synchronisation 2 Answers

How to PollHostList already running as server? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges