bckobayashimaru.de

Bridge Commander Kobayashi Maru Project
It is currently Tue Jun 25, 2019 3:28 am

All times are UTC




Post new topic Reply to topic  [ 42 posts ]  Go to page Previous  1, 2, 3  Next
Author Message
 Post subject:
PostPosted: Sun Jan 14, 2007 7:07 pm 
Offline
Cadet 1st Year
Cadet 1st Year

Joined: Tue Jan 31, 2006 1:13 am
Posts: 14
Whoa! This topic is still here!

I confess, I'm not really sure what a good MP script would be. Having read more than one MP script, I remain baffled at why certain things have to be sent as messages between the player computers and other things don't. So... first things first, what makes a script good for adaptation to MP?


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sun Jan 14, 2007 8:50 pm 
Offline
Chief Engineer
Chief Engineer
User avatar

Joined: Fri May 06, 2005 10:41 am
Posts: 2449
Location: Hamburg, Germany
oh I have a cool idea for a script that we can make MP compatible: The shuttle launching framework - right now it does work, but the shuttle counter is not correctly decremented on all hosts; only on the host that is launching the shuttle.

Wowbagger wrote:
Whoa! This topic is still here!

Surprised? - Afaik mysql is not known for loosing data.

Wowbagger wrote:
I confess, I'm not really sure what a good MP script would be.

Well it
1) is simple
2) just works
3) secure

I was never able to reach the 3rd point...

Wowbagger wrote:
So... first things first, what makes a script good for adaptation to MP?

Actually every script should be adapted for MP. First you should test it if it does work with any modification. If not, you probably have to communicate between the hosts

shall we begin?

_________________
Shuttle Launching Framework carrier file creator

--
Whenever you find that you are on the side of the majority, it is time to reform.
-- Mark Twain


Last edited by Defiant on Sun Jan 14, 2007 10:08 pm, edited 4 times in total.

Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sun Jan 14, 2007 8:59 pm 
Offline
Chief Engineer
Chief Engineer
User avatar

Joined: Fri May 06, 2005 10:41 am
Posts: 2449
Location: Hamburg, Germany
Well ok lets start to categorize a script.

We have 4 main classes:
1) Stuff that does work without any problems (like inaccurate phasers)
2) Stuff that does work with some work, mostly sending mp messages. (like Self Destruct)
3) Host only things, like AI Shuttle Launching
4) things that just won't work:
-changing a player ship (Will work in KM 1.0 with a heavy work around)
-change some ship attributes like maximum impulse.

Note: The host is the exception: The Host can always do everything.

Most times when adopting a script for MP you will try to sync server informations with the clients.

So what is the difference between inaccurate phasers, self destruct and Surrender? Why do AI shuttle launching and inaccurate phasers work without a problem, but self destruct doesn't?

Simple. Inaccurate phasers does work, because all clients do know when a ship fires a phaser and - because we have no random element in it - all the clients only needs to do the same calculations.

AI Shuttle launching does work. because the calculations needs to be done only once: So the logical choice is to let the host do the calculations.

Now Self destruct doesn't work, because we use pShip.DestroySystem(pShip.GetHull()) to destroy the ship.
This is not forwarded to the other clients!
So in this case solution is to listen on all clients for ET_OBJECT_EXPLODING, because pShip.DestroySystem(pShip.GetHull()) is caught by this event!

So when a client does catch this event it will send a message to the others that it got this event, so the other clients can also do pShip.DestroySystem(pShip.GetHull()) on their end.

There is no rule when to use messages: You have to test your script in MP.
If it does not work, you have to find out, why. You have to think a lot here. In most cases it does not work, because the other clients are missing an information you have to deliver. I will post some examples soon.

So much for lesson one.
Next lesson: How do I send and receive messages and what messages currently exists.

_________________
Shuttle Launching Framework carrier file creator

--
Whenever you find that you are on the side of the majority, it is time to reform.
-- Mark Twain


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sun Jan 14, 2007 11:39 pm 
Offline
Ensign
Ensign

Joined: Mon Jul 18, 2005 9:33 pm
Posts: 104
Defiant wrote:
Well ok lets start to categorize a script.

4) things that just won't work:
-changing a player ship (Will work in KM 1.0 with a heavy work around)
-change some ship attributes like maximum impulse.

Note: The host is the exception: The Host can always do everything.

Most times when adopting a script for MP you will try to sync server informations with the clients.

Now Self destruct doesn't work, because we use pShip.DestroySystem(pShip.GetHull()) to destroy the ship.
This is not forwarded to the other clients!
So in this case solution is to listen on all clients for ET_OBJECT_EXPLODING, because pShip.DestroySystem(pShip.GetHull()) is caught by this event!

So when a client does catch this event it will send a message to the others that it got this event, so the other clients can also do pShip.DestroySystem(pShip.GetHull()) on their end.


if i understand what you said here, im just a little curious. you mentioned events like ET_OBJECT_EXPLODING. what are the chances of scripts that just don't work in MP being modified to use events like the one you mentioned above that will enable them to work in MP? what other handlers, if any, other than events will work in MP?

_________________
Sitting, for hours on end, levelling up whilst putting up with tirades of nonsense/idiots/abuse and avoiding the Killer Bunny Rabbit of Doom that will most certainly kill you if you face up to it. - Ian Dransfield, Prodigious Gaming


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Mon Jan 15, 2007 8:16 am 
Offline
Chief Engineer
Chief Engineer
User avatar

Joined: Fri May 06, 2005 10:41 am
Posts: 2449
Location: Hamburg, Germany
Resistance Is Futile wrote:
if i understand what you said here, im just a little curious. you mentioned events like ET_OBJECT_EXPLODING. what are the chances of scripts that just don't work in MP being modified to use events like the one you mentioned above that will enable them to work in MP? what other handlers, if any, other than events will work in MP?

Also there is no rule here.
pShip.DestroySystem(pShip.GetHull()) doesn't seem to be catched by any exploding event.

Here is another example: ET_OBJECT_CREATED does only work on the host, that really creates the ship. But ET_OBJECT_CREATED_NOTIFY does work on other hosts.
So you may think now that it is a good idea to always use ET_OBJECT_CREATED_NOTIFY. No. You have to listen for both. (Don't ask me why, I'm not sure atm, but I think it was the problem that the NOTIFY handler is not always called in QB).

This tutorial can not give you a solution for every problem, but it should give you the right methods to solve most problems.

_________________
Shuttle Launching Framework carrier file creator

--
Whenever you find that you are on the side of the majority, it is time to reform.
-- Mark Twain


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Mon Jan 15, 2007 8:24 pm 
Offline
Cadet 1st Year
Cadet 1st Year

Joined: Tue Jan 31, 2006 1:13 am
Posts: 14
Fascinating. So there's no "magic formula" for MP-compatibilty testing.

I'm going to go check out a few random modded scripts in my QBA folder and see what happens. Fun!


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Mon Jan 15, 2007 11:49 pm 
Offline
Ensign
Ensign

Joined: Mon Jul 18, 2005 9:33 pm
Posts: 104
lol @ wowbagger. i know what you mean.

now if there was only a way around that dam Set. function, then we'd be in business :)

_________________
Sitting, for hours on end, levelling up whilst putting up with tirades of nonsense/idiots/abuse and avoiding the Killer Bunny Rabbit of Doom that will most certainly kill you if you face up to it. - Ian Dransfield, Prodigious Gaming


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sun Jan 28, 2007 4:03 pm 
Offline
Chief Engineer
Chief Engineer
User avatar

Joined: Fri May 06, 2005 10:41 am
Posts: 2449
Location: Hamburg, Germany
lesson 2: how to sent, receive a message and what messages currently exists in KM.

Example sending a message:
Code:
# Setup the stream.
# Allocate a local buffer stream.
kStream = App.TGBufferStream()
# Open the buffer stream with a 256 byte buffer.
kStream.OpenBuffer(256)
# Write relevant data to the stream.
# First write message type.
kStream.WriteChar(chr(SET_GET_SHIP_ATTR_MSG))

kStream.WriteInt(1) # set
kStream.WriteInt(pShip.GetObjID())
kStream.WriteInt(iShipFromID)

pMessage = App.TGMessage_Create()
# Yes, this is a guaranteed packet
pMessage.SetGuaranteed(1)
Okay, now set the data from the buffer stream to the message
pMessage.SetDataFromStream(kStream)
pNetwork = App.g_kUtopiaModule.GetNetwork()
if not App.IsNull(pNetwork):
    # Send the message to host
    pNetwork.SendTGMessage(pNetwork.GetHostID(), pMessage)
# We're done.  Close the buffer.
kStream.CloseBuffer()


So what do we do here?
The first lines will always be the same: Some mystic BC stuff.
The first important line is
Quote:
kStream.WriteChar(chr(SET_GET_SHIP_ATTR_MSG))

This line tells us what information we want to sent. In this case it seems to have anything to do with ship attributes.
This number here should also be coordinated with all other scripters. So it can not be used for two different things.

With the next 3 lines we send our information
Quote:
kStream.WriteInt(1) # set
kStream.WriteInt(pShip.GetObjID())
kStream.WriteInt(iShipFromID)

ok looks like we are sending 3 integers here. (I will tell you the information behind these 3 integers later. For now, they are just 3 numbers.

Most commonly you want to send integers or strings.
To send strings do this:
Code:
iLen = len(pcString)
kStream.WriteShort(iLen)
kStream.Write(pcString, iLen)

Should be easy to understand: We first sent the len of the string we want to send, then the string.

ok, our information is prepared. lets finally send the message.
Code:
pMessage = App.TGMessage_Create()
# Yes, this is a guaranteed packet
pMessage.SetGuaranteed(1)
Okay, now set the data from the buffer stream to the message
pMessage.SetDataFromStream(kStream)
# Send the message to host
pNetwork = App.g_kUtopiaModule.GetNetwork()

The usual bc stuff here....

Code:
pNetwork.SendTGMessage(pNetwork.GetHostID(), pMessage)

This will send the message to the host only.
The other possible value here is
Code:
if App.g_kUtopiaModule.IsHost():
    pNetwork.SendTGMessageToGroup("NoMe", pMessage)

You can only send a message
from the host to all clients
or
from a client to the host.
(Sending a message from a host to a single client is probably also possible but I never tried or needed it)

So if you want to send a message from a clients to all clients you have to:
1. send the message to the host
2. let the host forward the message to all clients.

You probably want to setup these functions:
Code:
def CreateMessageStream(iMessageType):
   debug(__name__ + ", CreateMessageStream")
   pNetwork = App.g_kUtopiaModule.GetNetwork()
   pMessage = App.TGMessage_Create()
   pMessage.SetGuaranteed(1)
   kStream = App.TGBufferStream()
   kStream.OpenBuffer(256)
   kStream.WriteChar(chr(iMessageType))
   return pMessage, kStream


def SendMessageToEveryone(pMessage, kStream):
   debug(__name__ + ", SendMessageToEveryone")
   pNetwork = App.g_kUtopiaModule.GetNetwork()
   pMessage.SetDataFromStream(kStream)
   if not App.IsNull(pNetwork):
      if App.g_kUtopiaModule.IsHost():
         pNetwork.SendTGMessageToGroup("NoMe", pMessage)
      else:
         pNetwork.SendTGMessage(pNetwork.GetHostID(), pMessage) # Host has to forward for us
   kStream.CloseBuffer()


def SendMessageToHost(pMessage, kStream):
   debug(__name__ + ", SendMessageToHost")
   pNetwork = App.g_kUtopiaModule.GetNetwork()
   pMessage.SetDataFromStream(kStream)
   if not App.IsNull(pNetwork):
      pNetwork.SendTGMessage(pNetwork.GetHostID(), pMessage)
   kStream.CloseBuffer()

in KM you will find them in scripts/Custom/MultiplayerExtra/MultiplayerLib/

So to send a message you only need to
Code:
pMessage, kStream = CreateMessageStream(DELETE_OBJECT_FROM_SET_MSG)
kStream.WriteInt(pShip.GetObjID())
SendMessageToEveryone(pMessage, kStream)

_________________
Shuttle Launching Framework carrier file creator

--
Whenever you find that you are on the side of the majority, it is time to reform.
-- Mark Twain


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sun Jan 28, 2007 5:19 pm 
Offline
Chief Engineer
Chief Engineer
User avatar

Joined: Fri May 06, 2005 10:41 am
Posts: 2449
Location: Hamburg, Germany
So now to receive messages we first need to set up an event handler:
Code:
App.g_kEventManager.AddBroadcastPythonFuncHandler(App.ET_NETWORK_MESSAGE_EVENT, pMission, __name__ + ".ProcessMessageHandler")


Code:
def ProcessMessageHandler(pObject, pEvent):
   debug(__name__ + ", ProcessMessageHandler")
   pMission = MissionLib.GetMission()
   if (pMission == None):
      # Mission is over, don't process messages.
      return

   pMessage = pEvent.GetMessage()
   if pMessage:
      # Get the data from the message
      # Open a buffer stream to read the data
      kStream = pMessage.GetBufferStream();

      cType = kStream.ReadChar();
      cType = ord(cType)

You see it is in someway similar to the send message stuff above

Code:
if cType == SET_SHIELD_CONDITION:
    ObjectId = kStream.ReadInt()
    iShield = kStream.ReadInt()
    iNewCondition = kStream.ReadInt()
    pShip = App.ShipClass_GetObjectByID(None, ObjectId)
    if pShip:
        pShields = pShip.GetShields()
        if pShields:
            pShields.SetCurShields(iShield, iNewCondition)

Should be easy to understand: We decode 3 integer here and then do some magic with them

Finally don't forget this:
Code:
kStream.Close()


Next lesson: What messages currently exists.

_________________
Shuttle Launching Framework carrier file creator

--
Whenever you find that you are on the side of the majority, it is time to reform.
-- Mark Twain


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Fri Feb 02, 2007 2:19 pm 
Offline
Chief Engineer
Chief Engineer
User avatar

Joined: Fri May 06, 2005 10:41 am
Posts: 2449
Location: Hamburg, Germany
What messages currently exists?

REMOVE_POINTER_FROM_SET = 190
For Firepoints, will remove a firepoint from the set.
Shouldn't be used anymore


REMOVE_TORP_MESSAGE_AT = 191
Will remove a torpedo from the set (PointDefence)
Int Sender Host ID
Float (Torpedo x coord)
Float (Torpedo y coord)
Float (Torpedo z coord)


NO_COLLISION_MESSAGE = 192
Will disable collision between two objects
Int Object ID 1
Int Object ID 2
Int 0 = Disable, 1 = Enable


DISABLE_TRACTOR_MESSAGE = 193
script specific, you shouldn't need this


SUBSYSTEM_SET_CONDITION = 194
Changes the condition of a subsystem
int Object ID
char subsystem name
..
char '\0'
int new condition


MP_SET_TRACTOR_MODE = 195
int Object ID
int Tractor mode


SET_SCRIPT_MSG = 196
Does set pShip.SetScript(). Shouldn't be used any more


ET_CLIENT_SCAN = 197
KM Cloak counter measures stuff


MP_REMOTE_CONTROL_MSG = 198
Remote execution of python commands.


SET_SHIELD_CONDITION = 199
never used?


MP_SET_POSITION_MSG = 200
Will move an object to a position
int Object ID
int 0 = Do not align to vectors
3 * float x,y,z pos
3 * float xy,z forward
3* float x,y,z up



MP_SEND_WARP_SPEED_MSG = 201
You shouldn't need this


MP_SEND_PLASMA_FX = 202
You shouldn't need this


PLAYER_NOW_USING_SHIP = 203
Outdated


INACCURATE_PHASERS_COMMUNICATION = 204
You shouldn't need this


MP_NEW_NET_PLAYER_ID = 205
Outdated


MP_WARP_ETA_MSG = 206
You shouldn't need this


MP_CONSTRUCT_MSG = 207
You shouldn't need this


REPLACE_MODEL_MSG = 208
Replaces a ships model
int Object ID
string new model


SET_TARGETABLE_MSG = 209
Sets targetable on an object
int Object ID
int 1 or 0


ALERT_STATE_CHANGED_MSG = 210
You shouldn't need this


DELETE_OBJECT_FROM_SET_MSG = 211
Will delete an object from the set
int object id


SET_GET_SHIP_ATTR_MSG = 212
Just hope you will never need this


SET_AUTO_AI_MSG = 213
calls autoAI() for a ship
int object id


SET_STOP_AI_MSG = 214
will remove an AI from a ship
int object id


TRACTOR_STARTED_MSG = 215
You shouldn't need this

_________________
Shuttle Launching Framework carrier file creator

--
Whenever you find that you are on the side of the majority, it is time to reform.
-- Mark Twain


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Fri Feb 02, 2007 2:19 pm 
Offline
Chief Engineer
Chief Engineer
User avatar

Joined: Fri May 06, 2005 10:41 am
Posts: 2449
Location: Hamburg, Germany
still following?

_________________
Shuttle Launching Framework carrier file creator

--
Whenever you find that you are on the side of the majority, it is time to reform.
-- Mark Twain


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Fri Feb 02, 2007 2:22 pm 
Offline
Cadet 2nd Year
Cadet 2nd Year
User avatar

Joined: Sun Jun 26, 2005 3:56 pm
Posts: 45
Location: Netherlands
Yeah, think so atleast.

Though I'll read it through a couple more times later.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sun Feb 25, 2007 10:14 am 
Offline
Lieutenant
Lieutenant

Joined: Mon Dec 26, 2005 12:23 am
Posts: 263
For the one's where you say you "shouldnt need this" etc, is this because you've scripted alternatives in to KM therefore they become deprecated?

In that case this tutorial only really applies to KM doesnt it.

_________________
By reading my messages you agree wholely and entirely to indemnity. Therefore, if as a result you die from reading these messages; i am exempt from prosecution.

"Turns on the seizure machine and projects it towards phone socket"


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sun Feb 25, 2007 10:17 am 
Offline
Chief Engineer
Chief Engineer
User avatar

Joined: Fri May 06, 2005 10:41 am
Posts: 2449
Location: Hamburg, Germany
They cover basic problems that are automatically corrected by the latest Turkey Shoot version.

_________________
Shuttle Launching Framework carrier file creator

--
Whenever you find that you are on the side of the majority, it is time to reform.
-- Mark Twain


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sun Feb 25, 2007 10:21 am 
Offline
Lieutenant
Lieutenant

Joined: Mon Dec 26, 2005 12:23 am
Posts: 263
Congratulations, you should work in tech support, they never answer the question.

Turkey Shoot is KM specific, therefore, shall we assume for stupidities sake that any one of the message that you put "Shouldnt be used anymore" or "You shouldnt need this", outside of KM you willl need or should be used, wont it? :evil:

_________________
By reading my messages you agree wholely and entirely to indemnity. Therefore, if as a result you die from reading these messages; i am exempt from prosecution.

"Turns on the seizure machine and projects it towards phone socket"


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 42 posts ]  Go to page Previous  1, 2, 3  Next

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


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
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group