Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Server States (Open, Closed, Locked)
#1
Thanks dave, this is much easier than setting up a separate test server lol. Can just boot everyone off and do your work. Which is nice Smile

I also took the liberty of posting my own code. I hope you don't mind. If so, delete it :p. I'll understand. I just think it's a good feature and it is relatively easy to implement. Regardless, here it is, free of charge:

***************************************************************

Difficulty: 2/5

This is of great use to me, and I'm sure other will use it to. Thanks to Dave for the tutorial.

This is my code, the messages and such can be changed to suit your liking.

Open up frmServer and click the menu editor.

Add the following things to the menu:
Code:
&Server States
        Caption: &Server States
        Name: mnuStates
        Checked: UnChecked
----Open
        Caption: Open
        Name: mnuOpen
        Checked: Checked
----Close
        Caption: Close
        Name: mnuClose
        Checked: UnChecked
----Locked
        Caption: Locked
        Name: mnuLocked
        Checked: UnChecked

Click OK.

Now, Click on the &Server States menu, and click Open.
Add this code to the sub routine:
Code:
If mnuOpen.Checked = False Then
        mnuOpen.Checked = True
        mnuClose.Checked = False
        mnuLocked.Checked = False
        ServerState = STATE_OPEN
        
        Call GlobalMsg("The server is now running in Open State!", GlobalColor)
    End If

Now, Click on the &Server States menu, and click Close.
Add this code to the sub routine:
Code:
If mnuClose.Checked = False Then
        mnuOpen.Checked = False
        mnuClose.Checked = True
        mnuLocked.Checked = False
        ServerState = STATE_CLOSE
        
        Call GlobalMsg("The server is now running in Closed State!", GlobalColor)
    End If
    
    Dim i As Long
    
    For i = 1 To MAX_PLAYERS
        If IsPlaying(i) Then
            If GetPlayerAccess(i) < ADMIN_MONITER Then
                Call AlertMsg(i, "Sorry, the server has been closed to the public. You have been disconnected. Watch the forum for a post regarding this.")
            End If
        End If
    Next i

As Dave explained above, this is the code used to boot the players off the server. This code shown here will boot anyone with an access level of 0 and send a global message notifying other admins that the server state has been changed. For those of you who don't know, the AlertMsg command sends a pop up message to the user then disconnects them from the server. They click OK to clear the message and their client will close. Thus, removing them from the game.

Now, Click on the &Server States menu, and click Locked.
Add this code to the sub routine:
Code:
If mnuLocked.Checked = False Then
        mnuOpen.Checked = False
        mnuClose.Checked = False
        mnuLocked.Checked = True
        ServerState = STATE_LOCKED
        
        Call GlobalMsg("The server is now running in Locked State!", GlobalColor)
    End If
    
    Dim i As Long
    
    For i = 1 To MAX_PLAYERS
        If IsPlaying(i) Then
            If GetPlayerAccess(i) < ADMIN_DEVELOPER Then
                Call AlertMsg(i, "The server has been restricted to admin only access. You have been disconnected. Watch the forum for a post regarding this.")
            End If
        End If
    Next i

This does the same thing as the above sub routine, except it boots everyone who is of Access level 0, 1 and 2.

Now, open up modConstants and add the following to the botton of the module:
Code:
' Server state constants
Public Const STATE_OPEN = 1
Public Const STATE_CLOSE = 2
Public Const STATE_LOCKED = 3

Now, open up modGlobals and add this:
Code:
' Server State var
Public ServerState As Byte

Open up modHandleData and search for "usechar".

After this line:
Code:
Player(index).Charnum = Charnum

Add this:
Code:
If ServerState = STATE_LOCKED Then
                    If GetPlayerAccess(index) < 3 Then
                        Call AlertMsg(index, "Sorry, the server has been restricted to admin only access. Check the message board for details.")
                    End If
                    Exit Sub
                ElseIf ServerState = STATE_CLOSE Then
                    If GetPlayerAccess(index) < 1 Then
                        Call AlertMsg(index, "Sorry, the server has been restricted to moderator only access. Check the message board for details.")
                    End If
                    Exit Sub
                End If

That's it, I feel like I may have forgotten something, so if so, tell me and I'll edit this post Smile. Enjoy Big Grin
Reply
#2
I think this had an old tutorial, a looong ago, since I have this stuff on my game and I KNOW I didn't developed it. Just can't remember who did it...
Reply
#3
Yea, well Im still sort of a newb at this lmao, I didn't know what an Enum was until about 12 hours ago when I searched for it Tongue
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)