vbGore Free Online RPG Engine

Revolutionizing Visual Basic ORPG Development
It is currently Wed May 22, 2013 4:28 pm

All times are UTC - 8 hours




Post new topic This topic is locked, you cannot edit posts or make further replies.  [ 30 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Gettting data realtime
PostPosted: Sun Feb 01, 2009 11:39 am 
Bit Baby

Joined: Sun Jul 20, 2008 5:48 pm
Posts: 387
Location: Mercer Island , Washington
Where is /how is the server sending the info about health/mana realtime or where/how is the client requesting this data realtime. The goal is to read from the database how many points the battle team has, and put this in a window. I have team battles done, if you care to see it:

Code:

Sub Data_TeamBattle(ByRef rbuf As DataBuffer, ByVal UserIndex As Integer)
Dim i As Long
Dim mapnum As Integer 'map with least
Dim n As Integer 'number of players
Dim team1 As Integer
Dim team2 As Integer
Dim myteam As Integer

'get most populated battlemap
DB_RS.Open "SELECT * FROM battlemap ORDER BY players desc"
Do
mapnum = DB_RS!Map
n = DB_RS!players
DB_RS.MoveNext
Loop Until n <= 2 'max players
DB_RS!players = DB_RS!players + 1
mapnum = DB_RS!Map
DB_RS!team1 = mapnum * 3
DB_RS!team2 = mapnum * 3 + 1
DB_RS.Update
DB_RS.Close

'Join lowest amount team to balance out
DB_RS.Open "SELECT *  FROM battlemap WHERE `map`='" & mapnum & "'"
team1 = DB_RS!team1players
team2 = DB_RS!team2players
If team1 > team2 Then
myteam = DB_RS!team2
DB_RS!team2players = DB_RS!team2players + 1
Else
myteam = DB_RS!team1
DB_RS!team1players = DB_RS!team1players + 1
End If
DB_RS.Update
DB_RS.Close

'Update users team
DB_RS.Open "SELECT * FROM users WHERE `name`='" & UserList(UserIndex).Name & "'"
DB_RS!team = myteam
DB_RS.Update
DB_RS.Close

User_WarpChar UserIndex, mapnum, 1, 1

End Sub

Sub Data_TeamBattle_Leave(ByRef rbuf As DataBuffer, ByVal UserIndex As Integer)
Dim n As Integer 'number of players
Dim currmap As Integer 'map user is on right now
Dim myteam As Integer

currmap = UserList(UserIndex).Pos.Map

'remove player from team
DB_RS.Open "SELECT * FROM users WHERE `name`='" & UserList(UserIndex).Name & "'"
myteam = DB_RS!team
DB_RS!team = 0
DB_RS.Update
DB_RS.Close

If myteam / 3 = currmap Then
DB_RS.Open "SELECT *  FROM battlemap where `map`='" & currmap & "'"
DB_RS!players = DB_RS!players - 1
DB_RS!team1players = DB_RS!team1players - 1
DB_RS.Update
DB_RS.Close
Else
DB_RS.Open "SELECT *  FROM battlemap where `map`='" & currmap & "'"
DB_RS!players = DB_RS!players - 1
DB_RS!team2players = DB_RS!team2players - 1
DB_RS.Update
DB_RS.Close
End If
User_WarpChar UserIndex, 16, 14, 4
End Sub


Top
 Profile  
 
 Post subject: Re: Gettting data realtime
PostPosted: Sun Feb 01, 2009 12:31 pm 
Aleron Coder

Joined: Fri Jan 05, 2007 5:36 am
Posts: 2964
Location: Germany
are you using the database in REALTIME?! O_o
you should load the DB into the server and send between server and clients.
a realtime traffic between database and server is like omg...


Top
 Profile  
 
 Post subject: Re: Gettting data realtime
PostPosted: Sun Feb 01, 2009 12:35 pm 
Slave to the BB

Joined: Sat May 12, 2007 6:20 am
Posts: 3842
Location: Behind you!
Zanval refer here :P
viewtopic.php?p=86658#p86658

That will explain why he's doing it.


Top
 Profile  
 
 Post subject: Re: Gettting data realtime
PostPosted: Sun Feb 01, 2009 4:17 pm 
Bit Baby

Joined: Sun Jul 20, 2008 5:48 pm
Posts: 387
Location: Mercer Island , Washington
Nevermind, I am using a timer and all should be well.


Top
 Profile  
 
 Post subject: Re: Gettting data realtime
PostPosted: Mon Feb 02, 2009 4:11 am 
Bit Baby

Joined: Tue Sep 02, 2008 12:33 pm
Posts: 382
Location: United Kingdom
Don't use an actual timer component! o.O


Top
 Profile  
 
 Post subject: Re: Gettting data realtime
PostPosted: Mon Feb 02, 2009 2:44 pm 
Bit Baby

Joined: Sun Jul 20, 2008 5:48 pm
Posts: 387
Location: Mercer Island , Washington
already am, it works wonders. it checks if the point window is open though, so dont worry bout bandwith


Top
 Profile  
 
 Post subject: Re: Gettting data realtime
PostPosted: Tue Feb 03, 2009 1:17 am 
Slave to the BB

Joined: Tue Jul 31, 2007 8:45 am
Posts: 3273
Location: United Kingdom
I think this is a lost cause.


Top
 Profile  
 
 Post subject: Re: Gettting data realtime
PostPosted: Tue Feb 03, 2009 3:35 am 
Richardf's Evil Minion

Joined: Fri Apr 20, 2007 5:38 am
Posts: 109
geolej, you will be getting MASSIVE time-outs in real game.
I would suggest moving battlemap to server-array and checking all those values within code.

Also, your myteam value doesn't make any sense. Why you didn't create new User-object property and use it like all other properties are used already?


Top
 Profile  
 
 Post subject: Re: Gettting data realtime
PostPosted: Wed Feb 04, 2009 7:47 pm 
+7 Claymore of Slaying

Joined: Thu Dec 21, 2006 6:24 pm
Posts: 594
Location: Land made of long cloud. Wait no its Land of white clouds. Actually i think its New Zealand.
@geolej
1. You should NEVER use database in realtime its a waste of bandwidth no matter what you do.
2. Use arrays in the server. Load up the info from db once and save the info to the database every so often.
3. VB6 timers is usually real crap so use the TimeGetTime instead.

Follow these and you will save yourself alot of bandwidth, lag and any other issues you may encounter from making queries to your database.


Top
 Profile  
 
 Post subject: Re: Gettting data realtime
PostPosted: Thu Feb 05, 2009 5:06 am 
Richardf's Evil Minion

Joined: Fri Apr 20, 2007 5:38 am
Posts: 109
Enternaldr, I could argue about using live database connection in in-game mail system.
As you just want to send something, and remember it in DB, it won't harm using sql connection there.

For other purposes - agree, its waste of bandwidth.


Top
 Profile  
 
 Post subject: Re: Gettting data realtime
PostPosted: Thu Feb 05, 2009 5:19 am 
baka

Joined: Tue Jul 08, 2008 12:17 am
Posts: 2304
Location: England, UK
rochal wrote:
Enternaldr, I could argue about using live database connection in in-game mail system.
As you just want to send something, and remember it in DB, it won't harm using sql connection there.

For other purposes - agree, its waste of bandwidth.

I don't see why that would be any different to anything else, you could just store it in a string array in the server then dump it to the database periodically with everything else.


Top
 Profile  
 
 Post subject: Re: Gettting data realtime
PostPosted: Thu Feb 05, 2009 7:22 am 
Richardf's Evil Minion

Joined: Fri Apr 20, 2007 5:38 am
Posts: 109
2 scenarios:

1. Update all users mailboxes every 10 seconds.

2. Update user A mailbox when he wants to see his mailbox.


Which one you think is more proficient?


Top
 Profile  
 
 Post subject: Re: Gettting data realtime
PostPosted: Thu Feb 05, 2009 7:30 am 
baka

Joined: Tue Jul 08, 2008 12:17 am
Posts: 2304
Location: England, UK
Well updating periodically would be more efficient.

You could create a kind of pseudo mail server built into the main server that could handle mailboxes and update them whenever mail arrived, and it could save the mailbox data to the database periodically like everything else does. I don't see why you'd need to constantly connect with the database just to check mail.


Top
 Profile  
 
 Post subject: Re: Gettting data realtime
PostPosted: Thu Feb 05, 2009 7:41 am 
Richardf's Evil Minion

Joined: Fri Apr 20, 2007 5:38 am
Posts: 109
Sorry, efficient is the word I should use.

I didnt say you need to be constantly connected to DB. in fact, constant connection with databse is big design mistake. You connect, you get what you need and you disconnect - always.

What Im saying is everytime when you want to check if any new mail arrived, you just execute simple call to Database, and fill up List<Mail> with new data about mails you have.

Also, you are talking about saving data - I'm talking about reading it. If I sent mail to other user it's pointless saying 'ok now wait 30 seconds till it get saved to databse, and then resend back to you'. To make it quick one single call to database will solve the problem.


Top
 Profile  
 
 Post subject: Re: Gettting data realtime
PostPosted: Thu Feb 05, 2009 7:53 am 
baka

Joined: Tue Jul 08, 2008 12:17 am
Posts: 2304
Location: England, UK
You misunderstand :P

Say you load the server up, it'll connect to the DB and read all of the mail for User 1 and User 2. User 1 sends User 2 a mail, the server adds the mail to an array in memory, now say User 2 wants to check his mail, the server reads the mail from the array and sends the data to User 2. On top of this, every so often the server will save new mail to the DB (this would just be synchronised with any other periodic DB connections).

So all the mail is stored in memory while the server is running and is backed up periodically and is discarded if the user in question has logged off.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic This topic is locked, you cannot edit posts or make further replies.  [ 30 posts ]  Go to page 1, 2  Next

All times are UTC - 8 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group