Login and private message

Preview:

Citation preview

Web Game Design

授課教師江素貞

ElectroServer Design Concepts

Event Handlers ElectroServer currently allow event handlers to be created

for the following event types:

Login

Logout

User Variable─User has updated the EsObject attached to the

user object.

Room Variable ─User has updated the EsObject attached to

the room.

Buddy List─User has updated his buddy list (add/edit/delete).

Private/Public Messaging─User has sent a message to another

entity (room/user).

The ElectroServer API The ElectroServer API is an ActionScript 3 API use by a

multiplayer application to connect to and communicate with ElectroServer.

There are three main types of message that can travel in either direction between the client and the server.

Requests ─ Objects created by the client and then sent to the server. (LoginRequest)

Responses ─ Objects created by the server as a result of a request and then sent to the client. (LoginResponse)

Events ─ Messages (sent from the server to client) that did not necessarily originate from a request.

Prepare an ElectroServer Instance The first thing you need to do before connecting to

ElectroServer is create a new instance of the ElectroServerclass.

The ElectroServer class is the gateway to the entire API.

var es:ElectroServer = new ElectroServer();

Then we add event listeners, so that we can capture the responses and events that come back from the server.

es.addEventListener(…);

We should tell the API which protocol we want to use.

es.setProtocol(Protocol.XXX);

MessageType class This class stores static variables that act as a message

definition. All messages (requests, responses, events) have

a getMessageType() method. The value of it is one of the

static variables in this class.

ConnectionEvent

LoginResponse

PrivateMessageEvent

……

連線與登入流程 Main.as: new ConnServer

ConnServer.as: 處理連線與登入

Connect: 讀檔取得ip及port,createConnection()

Create Login UI: 連線成功後, new LoginScreen(),聆聽是否按下LoginScreen之[login]按鈕

Login: 讀取輸入之帳號名稱並登入伺服器,登入成功後,移除LoginScreen畫面

Send Message: 傳送訊息給自己測試

Send Private Message

(附件:Connection and Login Tutorial.docx)

Connect We make the connection attempt to ElectroServer.

es.createConnecton(“127.0.0.1”, 9898);

We add an event listener for the connection event.

es.addEventListener(MessageType.ConnectionEvent, “onConnecting”, this);

When the connection succeeds or fails, the onConnectingfunction is called:

public function onConnecting(e:ConnectionEvent):void

{

//e.getAccepted() 可判斷是否登入成功//e.getEsError().getDescription() 可取得錯誤訊息

}

Login To log in to ElectroServer, first a LoginRequest object is

creted, a username is populated onto that object.

var lr:LoginRequest = new LoginRequest();

lr.setUserName(“…”);

es.send(lr);

Capture the login response that send from server.

es.addEventListener(MessageType.LoginResponse,

“onLogin”, this);

Send a Private Message To send a private message with ElectroServer, you first create a

SendPrivateMessageRquest object.

var pmr:PrivateMessageRequest = new PrivateMessageRequest();

pmr.setUserNames([e.getUserName()])

pmr.setMessage(“Hello World!”);

es.send(pmr);

Capture the private message event is captured by:

public function onPrivateMessage(e:PrivateMessageEvent)

{

//e.getUserName() 取得送訊息者名字

//e.getMessage() 取得訊息內容

}

Recommended