Thiết kế chức năng của GameAS

Một phần của tài liệu Nghiên cứu cơ chế và giao thức phối hợp các phiên làm việc SIP(IMS) và (Trang 69 - 76)

4 CHƯƠNG Xây dựng hệ thống thử nghiệm cơ chế phối hợp giữa SIP và XML

4.2.1Thiết kế chức năng của GameAS

IMS Game Server Dang nhap Dang xuat Tao game choi game Ket thuc game

Cau hinh game

SIP-XML module <<include>> <<include>> <<include>> <<include>> <<include>> <<include>> <<include>> <<include>> <<include>> <<include>>

HÌNH 4-1 BIỂU ĐỒ USERCASE CỦA GAME AS

Chức năng của AS được thiết kế cơ bản nhất. Bao gồm các chức năng liên quan đến người dùng và logic trò chơi:

- Đăng nhập: cho phép người chơi đăng nhập vào hệ thống, sẵn sàng tạo game mới hoặc nhận lời mời chơi game.

- Đăng xuất: cho phép người chơi thoát ra khỏi hệ thống.

- Cấu hình game: cho phép người chơi thiết lập các cấu hình của game trước khi bắt đầu chơi, bao gồm các thiết lập về kích thước màn hình game…

Đỗ Đức Anh – CB120650 – KTTT1 2012B 59

- Tạo game, chơi game, kết thúc game: cho phép người chơi chơi game.

- SIP-XML module: thực hiện việc chuyển đổi dữ liệu từ bản tin SIP sang định dạng dữ liệu XML.

4.2.2 Thiết kế chi tiết chức năng của Game AS 4.2.2.1 Chức năng xác thực người dùng

HÌNH 4-2BIỂU ĐỒ TUẦN TỰ CHỨC NĂNG ĐĂNG NHẬP HỆ THỐNG

Thuật toán được sử dụng để xác thực người dùng

/********************************************************************/ /* Incoming message is REGISTER*/

if (strncmp(rdata->msg_info.msg->line.req.method.name.ptr, "REGISTER", rdata- >msg_info.msg->line.req.method.name.slen) == 0){

/* create response message */

pjsip_endpt_respond_stateless(globalPjCfg.endpt, rdata, PJSIP_SC_OK, &status_text, NULL, NULL);//200-OK

//anhdd 21.4.2015

pj_http_req;

//memset(&REG_msg, 0, sizeof(MES_DETAIL)); //REG_msg = mod_im_paser_msg(rdata);

REG_msg2 = mod_im_parse_msg2(globalPjCfg.pool, rdata);

sd Interactions

IMS Game AS Game Serv er

REGISTER(timeout = 3600)

ADD

SUCCESS

Đỗ Đức Anh – CB120650 – KTTT1 2012B 60 /* kiem tra contact trong database */

/* kiem tra xem truong To co trong imuser hay khong * neu co thi tiep tuc

* neu khong co thi bo qua, khong luu */

//iResult = mod_im_check_contact(REG_msg); (adsbygoogle = window.adsbygoogle || []).push({});

iResult = mod_im_check_user2(REG_msg2);

//if (REG_msg.iExpires != 0){//thuê bao online

if (iResult == DB_CONTACT_ONLINE){//thuê bao online /*************************************************/ // /* find & send verification*/

// memset(&MES_msg, 0, sizeof(MES_DETAIL));

// iResult = mod_dbs_load_verification_codes(REG_msg, &MES_msg); // if (iResult == DB_CONTACT_NOT_REGISTERED){

// iResult = mod_im_send_MESSAGE_verification(globalPjCfg.endpt, &mod_im_tu, MES_msg, REG_msg);

// if (iResult != PJ_SUCCESS){

// printf("send MESSAGE request error!\n");

// }

// }

/*************************************************/ /* find & send MESSAGE to Game server- status == -1 */ /**********************************************/

memset(to, 0, 32);

memset(sqlCmd, 0, 256);

pj_ansi_strncpy(to, REG_msg2.to.value.ptr, REG_msg2.to.value.slen);

pj_ansi_sprintf(sqlCmd, "select count(*) from IMMSG join IMUSER on

IMMSG.im_idto=IMUSER.im_iduser where IMUSER.im_number='%s' and IMMSG.im_status = -1", to);

iResult = mod_dbs_load_count2(sqlCmd, &iMESS_msg_offline_Count);

if (iMESS_msg_offline_Count > 0){

iResult = mod_dbs_load_MESS_offline2(globalPjCfg.pool, REG_msg2,

MES_msg_offline2, 32);

if (iResult != 0){

for (i=0; i<iMESS_msg_offline_Count; i++){ /* send MESSAGE message */

iResult = mod_im_send_MESSAGE_offline2(globalPjCfg.endpt, &mod_im_tu, rdata, MES_msg_offline2[i]);

if (iResult != PJ_SUCCESS){

printf("send MESSAGE request error!\n"); } } } } }//end of if (message.iExpires != 0) return PJ_TRUE; } //////////////////////////////////////////////////////////////////////////

Đỗ Đức Anh – CB120650 – KTTT1 2012B 61

HÌNH 4-3BIỂU ĐỒ TUẦN TỰ CHỨC NĂNG ĐĂNG XUẤT KHỎI HỆ THỐNG

4.2.2.2 Chức năng quản lý phiên chơi game

Thuật toán sử dụng để quản lý phiên chơi game. Game AS sẽ đón các bản tin request được gửi đến từ IMS-core và sẽ xử lý logic cho từng tình huống.

static pjsip_module mod_im_as = { (adsbygoogle = window.adsbygoogle || []).push({});

NULL, NULL, /* prev, next. */

{ "mod-instant-messaging-server", 28 }, /* Name. */ -1, /* Id */ PJSIP_MOD_PRIORITY_UA_PROXY_LAYER, /* Priority */ NULL, /* load() */ NULL, /* start() */ NULL, /* stop() */ NULL, /* unload() */

&im_on_rx_request, /* on_rx_request() */

&im_on_rx_response, /* on_rx_response() */

NULL, /* on_tx_request. */

NULL, /* on_tx_response() */

NULL, /* on_tsx_state() */

};

static pjsip_module mod_im_tu = {

NULL, NULL, /* prev, next. */

{ "mod-transaction-user", 20 }, /* Name. */ -1, /* Id */ PJSIP_MOD_PRIORITY_APPLICATION, /* Priority */ NULL, /* load() */ NULL, /* start() */ NULL, /* stop() */ NULL, /* unload() */ sd Interactions

IMS Game AS Game Serv er

REGISTER(timeout = 0)

REMOVE

SUCCESS

Đỗ Đức Anh – CB120650 – KTTT1 2012B 62

NULL, /* on_rx_request() */

NULL, /* on_rx_response() */

NULL, /* on_tx_request. */

NULL, /* on_tx_response() */

&im_on_tsx_state, /* on_tsx_state() */ };

/* The module instance. */

static pjsip_module mod_msg_logger = {

NULL, NULL, /* prev, next. */

{ "mod-msg-logger", 14 }, /* Name. */ -1, /* Id */ PJSIP_MOD_PRIORITY_TRANSPORT_LAYER-1,/* Priority */ NULL, /* load() */ NULL, /* start() */ NULL, /* stop() */ NULL, /* unload() */

&logging_on_rx_msg, /* on_rx_request() */ &logging_on_rx_msg, /* on_rx_response() */ &logging_on_tx_msg, /* on_tx_request. */ &logging_on_tx_msg, /* on_tx_response() */

NULL, /* on_tsx_state() */

};

/* This is the data that is attached to the UAC transaction */

struct uac_data{ (adsbygoogle = window.adsbygoogle || []).push({});

pjsip_transaction *uas_tsx;

pj_timer_entry timer;

};

/* This is the data that is attached to the UAS transaction */

struct uas_data{ pjsip_transaction *uac_tsx; }; GLOBAL_IM_CFG globalImCfg; GLOBAL_PJ_CFG globalPjCfg; DATE_TIME dateTime; /* Register module */

static pj_status_t init_instant_messaging_server(void){

pj_status_t status;

status = pjsip_endpt_register_module( globalPjCfg.endpt, &mod_im_as);

PJ_ASSERT_RETURN(status == PJ_SUCCESS, 1);

status = pjsip_endpt_register_module( globalPjCfg.endpt, &mod_im_tu);

PJ_ASSERT_RETURN(status == PJ_SUCCESS, 1); /* Register the logger module */

// pjsip_endpt_register_module(globalPjCfg.endpt, &mod_msg_logger);

/* Broadcast Msg */

return PJ_SUCCESS; }

Đỗ Đức Anh – CB120650 – KTTT1 2012B 63

HÌNH 4-4BIỂU ĐỒ TUẦN TỰ CHỨC NĂNG CẤU HÌNH GAME

HÌNH 4-5BIỂU ĐỒ TUẦN TỰ CHỨC NĂNG KHỞI TẠO GAME

sd Interactions

IMS Game AS Game Serv er

MESSAGE(config)

CONFIG

SUCCESS

200 OK

sd Interactions

IMS Game AS Game Serv er

MESSAGE(create)

CREATE

SUCCESS

Đỗ Đức Anh – CB120650 – KTTT1 2012B 64

HÌNH 4-6BIỂU ĐỒ TUẦN TỰ CHỨC NĂNG THAY ĐỔI DỮ LIỆU GAME (adsbygoogle = window.adsbygoogle || []).push({});

HÌNH 4-7BIỂU ĐỒ TUẦN TỰ CHỨC NĂNG KẾT THÚC GAME

sd Interactions

IMS Game AS Game Serv er

MESSAGE(modify)

MODIFY

SUCCESS

200 OK

sd Interactions

IMS Game AS Game Serv er

MESSAGE(delete)

DELETE

SUCCESS

Đỗ Đức Anh – CB120650 – KTTT1 2012B 65

Một phần của tài liệu Nghiên cứu cơ chế và giao thức phối hợp các phiên làm việc SIP(IMS) và (Trang 69 - 76)