Instance Map Script Help?

Started by chaucer, September 26, 2014, 08:26:34 pm

Previous topic - Next topic

chaucer

Ok back with a clear head, and my 2nd attempt at finding how to get and interpret data from server, (I'm using blizz abs controler for rmxos, it's alot less code to go through than rmx-os I hope that's ok)
class Scene_Map
 
  alias main_blizzabsrmxos_alias main
  def main
    main_blizzabsrmxos_alias

    $network.try_deactivate_gmaster <--#something like this I believe?
  end

but I'm not completely sure because try_deactivate gmaster is defined inside the same scrpt and it leads back to this
def try_deactivate_gmaster
    self.send('ABSGMD')
    @gmaster = false
  end

Actually the more I look at I think this is the opposite, this is sending a message to the server..
and if I'm right deactivating the gmaster is sending a message then activating it should be the opposite, but then that brings me back to this simillar code..
alias check_game_blizzabsrmxos_alias check_game
  def check_game(message)
    case message
    when /\AABSGMA\Z/ # global master activate
      @gmaster = true
      return true

don't know if I'm on the right track probably not lol but fingers crossed.

Ryex

you're getting it!

I think you main confusion is understanding how information is getting between the server and the client. don't worry this is both the most complex and simplest part for you. because while you may not understand it completely all the hard work has been done for you. you just have to learn how to use it.

I'll try to give a quick rundown of the principles.

The client and server are communicating over the internet, a process that can take an indeterminate amount of time. as such it's not as simple as just calling a method to send and receive data from a server.

All computers connected to the internet are given an IP (Internet Protocol) address, this address is a unique identifier for your location on the internet and while the intricacies are too large to explain here suffice it to say that the address is formatted in such a way that the network know how to get the message to any address by forwarding it along the chain.

there are many protocols for communication on the internet but the one used by the Client and Server in RMX-OS is called TCP (Transmission Control Protocol). Basically this protocol guarantees that a message gets to it's destination by requiring a response from the destination saying it got it. if no response is received it's resent ad infinitum until enough time has pass to say with some certainty that no response is coming. at which point it can be said that the connection "Timed out".

All this is taken care of for us by the underlying hardware of our computer's operating system, so all we have to know it that it works.

One other thing, How does a message sent to a computer get to the right application? The answer is ports. a computer has a bunch of numbered ports that a message can be sent to. by convention several of the numbers are reserved for specific things. port 80 for example is reserved for connections to an HTTP server running on the machine.

to receive messages an application must bind and listen to a port. when a message arrives the computer will forward the message to the application in a "you've got mail" way. typically "listening" to a port involved looping indefinitely and asking "is there a new message?" every time.

as you know RMXP has a graphics loop that goes on forever that involves updating positions of sprites etc. and then redrawing the screen. RMX-OS adds an additional step, check for messages.

I believe it's handled by $network.update

The server too has an indefinite loop that check for messages, one for every client (each loop is in it's own thread), every time there is a new message it calls all plugin's client_update method passing the message sent. if the plugins client_update method returns false it will keep processing the message passing it to each plugin and then trying to handle it itself.

so when your client_update plugin runs it is being run to process a message the client sent to the server.

Ruby object can't just be sent back and forth between the server and client they have to be reduced down to raw strings so when you process a message you're trying to pull the data back out of a string this is done with regular expressions and match groups to extract parts of the string

Message in RMX-OS follow a set form. First a Header, a series of letters (Capitals by convention) followed by raw data separated by tab characters "\t" for the arguments.

so sending messages back and forth from the server  is fairly simply for you. just call the networks send method and tap into the network's message checking methods to process the message the server sends back

Take a look at the network update method to see which methods you need to tap, then take a look at say the Blizz-ABS Controller to see how it aliases them and injects it's own case statement to check the messages.


Your task now should be to try and get the server to respond to an "INSTN" message with a "INSTM\t<instace_id>\t<real_id> message" to create a new instance and send the client to the instanced map.

I no longer keep up with posts in the forum very well. If you have a question or comment, about my work, or in general I welcome PM's. if you make a post in one of my threads and I don't reply with in a day or two feel free to PM me and point it out to me.<br /><br />DropBox, the best free file syncing service there is.<br />

chaucer

October 02, 2014, 10:25:44 pm #22 Last Edit: October 02, 2014, 11:41:22 pm by chaucer
Cool glad I was right! and as for not needing to understand it completely I would rather understand exactly what's going on knowing how to use something and knowing how something works are way different and I feel it's a step in the right direction knowing how things work. As the saying goes, "Give a man a fish and you feed him for a day; teach a man to fish and you feed him for a lifetime." lol. That being said thank you for the in-depth description of everything it gave me a much better understanding as of how the client and server communicate in RMX-OS. on to the next step hopefully I get it right this time.  :haha:

Edit:hmm.. I'm not completely sure I'm grasping this correctly, but this is what I got right now.
class Instance_Maps
 
  def get_instance(message)
   
    case message
    #I seen a (.+) not sure if i'm supposed to use it instead of (\d\d\d) I tried to google it with no avail.
    when /\AINSTN\t(.+)/ # not sure if this is correct?

      #and this is where the response should be right?(example below, also I'd have to define send_info)
      #$network.send_info(data here)

    end
  end
end


also I had seen you mentioned the "listen" part, and as well as the method for keeping maps updated in a loop, which i believe this is what you were referring to?
def wait_for_map_data

      # set waiting flag

      $game_temp.entering_map = true

      # wait for server to reply

      while $game_temp.entering_map

        $network.update_server_ping

        $network.listen

        Graphics.update

      end

    end


Am I going to need to alias this later on?(not sure if it's of any significance). Also sorry if this is all wrong haha I can be a slow learner at times.

Ryex

ok

sorry it took me so long to get back to you.

your still on the right path so don't worry

first an aside on regular expressions

Code: ruby
when /\AINSTN\t(.+)/


the when branches you're seeing are employing regular expressions. regular expressions are a language so to speak that describes how language is constructed and are typically used to define patterns to match against strings. Regexp, as they are sometimes called, as they are implemented today and in ruby in particular arose from the perl language.

in ruby strings delimited by // are considered regular expressions, there are other ways of constructing an regexp object by putting // around some text is by far the easiest

RMXP's help manual has a section on Regexp and you can google around for a multitude of references and tutorials

Here are the basics

there are special characters and sequences in regexp that define specific behavior the "\" character is probably the most important as it is used to escape other characters to form special charters.

for example the "\A" at the beginning of the regexp above matches the beginning of a string. "^" is somewhat similar except it matches the beginning of a line otherwise know as the beginning of a string or just after a "\n" also knows as a "new line" or a "line feed". additionally the "\t" references a tab character.

in regexp things between () - parentheses are known as match groups. () are used to mark out what parts of a matched pattern you're interested in and the matched teck can be pulled out useing them. in the case above we are interested in everything flowing the tab character till the end of the string

the ".+" is what matches everything. the "." character in a regexp  (unless escaped by a "\" -> "\.") matches any character at all including whitespace the "+" afterward is a modifier that matches one or more of the last pattern so ".+" means one or more of any character. "\d" matches any digit character (0-9).

the rest you can look up on your own.



OK now I'm going to describe everyplace you're going to need to modify to inject instance maps, I want you to try and identify every section on the list in the default scripts and RMX-OS including the server


  • client side, when changing maps the client send a message to the server with the id they are changing to

  • server side, where the client receives the change map message

  • Cient side, when loading the map screen the client loads server data before displaying the map (here is where you're going to receive the real map id to replace instance ids)

  • server side, where the server sends a client map data when they enter a new map

  • client side, where the client physical loads the map data and creates a tilemap



I no longer keep up with posts in the forum very well. If you have a question or comment, about my work, or in general I welcome PM's. if you make a post in one of my threads and I don't reply with in a day or two feel free to PM me and point it out to me.<br /><br />DropBox, the best free file syncing service there is.<br />

Blizzard

Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

chaucer

Ok so, sorry for the short absence, I didn't have access to my computer for a while, however i did read into the link blizz posted thanks for that it cleared up a lot cause I was pretty lost before i read your post haha not gonna lie. anyways I'll be able to continue this hopefully within the next few days. Just wanted to say I haven't given up on this, I'll inform my progress as soon as I can get around to it. Also Thanks again for all the help really appreciated.