Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[General] Adding new /commands
#1
MS4
v3.51

Adding new /commands like /kill or /mute have changed. They are now structured like the packet system.
Reference: http://web.miragesource.com/forums/viewt...331#p52200

HandleKeyPresses

Find
Code:
If Left$(MyText, 1) = "/" Then
            Command = Split(MyText, " ")

It will first get the text that you have typed in and will split it wherever a space is.
Example:
You type in "/info Admin".
The split function will then create the following array.
Command(0) = "/info"
Command(1) = "Admin"

So now we have to select what the command was and do something with it.
After
Code:
Select Case Command(0)
You'll have all the select statements.

Example
Code:
Case "/info"
                    ' Checks to make sure we have more than one string in the array
                    If UBound(Command) >= 1 Then
                        Call SendData(CPlayerInfoRequest & SEP_CHAR & Command(1) & END_CHAR)
                    End If

As you can see we have to add
Code:
If UBound(Command) >= 1 Then
This will be our error checking, since we know that we have to have the "/Command' and an additional piece of info, we have to make sure our array contains the right amount of elements.
If you know you need 4 pieces of info for your command you would have to do something like
Code:
If UBound(Command) >= 5 Then
1 for your command and 4 additional pieces of info.

Then you can access the strings in your command with
Code:
Command(NumberYouNeed)

Little thing on Val() to convert to a numerical value. It would be better to use the correct conversion.
For example if you know your string needs to be a long then you would do:
Code:
CLng(Command(1))

Clng() - Converts to a long
CInt() - Converts to an integer
Cbyte() - Converts to a byte

Now before we convert we want to make sure we have a valid number first.

A good check would be
Code:
If IsNumeric(Command(1)) Then
     SendSetAccess Command(2), CLng(Command(1))
End If

MAKE SURE TO CHECK ISNUMERIC BEFORE CONVERTING OTHERWISE YOU WILL GET ERRORS IF SOMEONE TYPES IN ANYTHING BESIDES A NUMBER.

I think that's it. If I'm missing something or didn't explain things well please let me know.
Reply
#2
Wow. Now things are complicated again. It's gonna take some time to get used to this again.
Reply
#3
It's a lot easier this way. You don't have to do letter counting or anything.

Let's say you have your "/mute player" command.

So you add
Code:
Case "/mute"
                    If UBound(Command) >= 1 Then
                        sendMutePlayer MyIndex, CLng(Command(1))
                    End If

Code:
If UBound(Command) >= 1 Then
That makes sure you have the command and the player to mute.

Code:
sendMutePlayer MyIndex, CLng(Command(1))
Psuedo code - dunno what your function is

And that's it to add the /command.
Reply
#4
so
all you do is really replace
sendMutePlayer MyIndex, CLng(Command(1))
correct?
Reply
#5
doomteam1 Wrote:so
all you do is really replace
sendMutePlayer MyIndex, CLng(Command(1))
correct?

And add in the
Code:
If UBound(Command) >= 1 Then
Reply
#6
Code:
sendMutePlayer MyIndex, CLng(Command(1))

The one is saying what word it is correct?
after 0 right
like
sendMuteplayer blah(command(1)
sendMuteServer blah(command(2)

or what?
cause i dont get the number
Reply
#7
This makes things a lot better.

However, all command handling should be in the server. You could send a packet like:

Code:
packet = "commands" & SEP_CHAR & Command(0)

If UBound(Command) > 0 Then
    packet = packet & SEP_CHAR & UBound(Command(0))
    For i = 1 To UBound(Command)
        packet = packet & SEP_CHAR & Command(i)
    Next i
Else
    packet = packet & SEP_CHAR & 0
End If

    packet = packet & END_CHAR

Server would do:

Code:
Select Case Parse$(1)
    If Val(Parse$(2)) = 0 Then
        Case "/help"
        'seperate the commands that are only single
    End If

    If Val(Parse$(2)) = 1 Then
        'seperate the commands that have a second parameter
        Case "/mute"
    End If
End Select

Something like that...thoughts?
Reply
#8
GIAKEN Wrote:This makes things a lot better.

However, all command handling should be in the server. You could send a packet like:

Code:
packet = "commands" & SEP_CHAR & Command(0)

If UBound(Command) > 0 Then
    packet = packet & SEP_CHAR & UBound(Command(0))
    For i = 1 To UBound(Command)
        packet = packet & SEP_CHAR & Command(i)
    Next i
Else
    packet = packet & SEP_CHAR & 0
End If

    packet = packet & END_CHAR

Server would do:

Code:
Select Case Parse$(1)
    If Val(Parse$(2)) = 0 Then
        Case "/help"
        'seperate the commands that are only single
    End If

    If Val(Parse$(2)) = 1 Then
        'seperate the commands that have a second parameter
        Case "/mute"
    End If
End Select

Something like that...thoughts?

I could go for a banana right now.
Quote:Robin:
Why aren't maps and shit loaded up in a dynamic array?
Jacob:
the 4 people that know how are lazy
Robin:
Who are those 4 people?
Jacob:
um
you, me, and 2 others?
Reply
#9
Robin Wrote:
GIAKEN Wrote:This makes things a lot better.

However, all command handling should be in the server. You could send a packet like:

Code:
packet = "commands" & SEP_CHAR & Command(0)

If UBound(Command) > 0 Then
    packet = packet & SEP_CHAR & UBound(Command(0))
    For i = 1 To UBound(Command)
        packet = packet & SEP_CHAR & Command(i)
    Next i
Else
    packet = packet & SEP_CHAR & 0
End If

    packet = packet & END_CHAR

Server would do:

Code:
Select Case Parse$(1)
    If Val(Parse$(2)) = 0 Then
        Case "/help"
        'seperate the commands that are only single
    End If

    If Val(Parse$(2)) = 1 Then
        'seperate the commands that have a second parameter
        Case "/mute"
    End If
End Select

Something like that...thoughts?

I could go for a banana right now.

Tarantulas lay their eggs in bananas.
Reply
#10
Personally I would leave them client side.

If you do the proper checks server side it wouldn't matter what they have access to on the client.
Reply
#11
Added a little bit about checking IsNumeric before using the conversion. This will protect you against RTEs.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)