Skip to content
GitLab
Explore
Sign in
Commits on Source (3)
duktape: Implement termsize()
· e828bf45
Andrew Price
authored
Jul 11, 2017
e828bf45
duktape: Implement ipc()
· d2e403b5
Andrew Price
authored
Jul 11, 2017
d2e403b5
duktape: Implement rpc()
· 7ee44b4e
Andrew Price
authored
Jul 11, 2017
7ee44b4e
Hide whitespace changes
Inline
Side-by-side
src/client/js-duk.c
View file @
7ee44b4e
...
...
@@ -177,6 +177,62 @@ static duk_ret_t js_wholist(duk_context *cx)
return
1
;
/* Array is returned at top of stack */
}
static
duk_ret_t
js_rpc
(
duk_context
*
cx
)
{
const
char
*
username
=
NULL
;
const
char
*
rpc_type
=
NULL
;
const
char
*
msg
=
NULL
;
int
broadcast
=
0
;
if
(
duk_is_undefined
(
cx
,
-
1
)
||
duk_is_undefined
(
cx
,
-
2
)
||
duk_is_undefined
(
cx
,
-
3
))
{
fprintf
(
stderr
,
"mwjs error: rpc() expects 3 arguments
\n
"
);
return
DUK_RET_SYNTAX_ERROR
;
}
if
(
duk_is_number
(
cx
,
-
3
))
{
if
(
duk_get_int
(
cx
,
-
3
)
==
K_BROADCAST
)
broadcast
=
1
;
}
else
if
(
duk_is_string
(
cx
,
-
3
))
{
username
=
duk_get_string
(
cx
,
-
3
);
}
rpc_type
=
duk_safe_to_string
(
cx
,
-
2
);
msg
=
duk_safe_to_string
(
cx
,
-
1
);
if
((
!
broadcast
&&
username
[
0
]
==
'\0'
)
||
rpc_type
[
0
]
==
'\0'
)
{
fprintf
(
stderr
,
"Error: javascript rpc(): invalid arguments - [%s] [%s]"
,
(
broadcast
?
"K_BROADCAST"
:
username
),
rpc_type
);
return
DUK_RET_ERROR
;
}
sendrpc
(
username
,
rpc_type
,
msg
,
broadcast
);
return
0
;
}
static
duk_ret_t
js_ipc
(
duk_context
*
cx
)
{
const
char
*
username
=
NULL
;
const
char
*
msg
=
NULL
;
int
broadcast
=
0
;
if
(
duk_is_undefined
(
cx
,
-
1
)
||
duk_is_undefined
(
cx
,
-
2
))
{
fprintf
(
stderr
,
"mwjs error: ipc() expects 2 arguments
\n
"
);
return
DUK_RET_SYNTAX_ERROR
;
}
if
(
duk_is_number
(
cx
,
-
2
))
{
if
(
duk_get_int
(
cx
,
-
2
)
==
K_BROADCAST
)
broadcast
=
1
;
}
else
if
(
duk_is_string
(
cx
,
-
2
))
{
username
=
duk_get_string
(
cx
,
-
2
);
}
msg
=
duk_safe_to_string
(
cx
,
-
1
);
if
(
broadcast
==
0
&&
(
!
username
||
username
[
0
]
==
'\0'
))
{
fprintf
(
stderr
,
"mwjs error: ipc() expects either a username or K_BROADCAST
\n
"
);
return
DUK_RET_ERROR
;
}
sendipc
(
username
,
msg
,
broadcast
);
return
0
;
}
static
duk_ret_t
js_beep
(
duk_context
*
cx
)
{
int
i
,
beeps
;
...
...
@@ -191,6 +247,18 @@ static duk_ret_t js_beep(duk_context *cx)
return
0
;
}
static
duk_ret_t
js_termsize
(
duk_context
*
cx
)
{
int
idx
;
idx
=
duk_push_bare_object
(
cx
);
duk_push_int
(
cx
,
screen_w
());
duk_put_prop_string
(
cx
,
idx
,
"width"
);
duk_push_int
(
cx
,
screen_h
());
duk_put_prop_string
(
cx
,
idx
,
"height"
);
return
1
;
/* Result is at top of stack */
}
static
duk_ret_t
js_bind
(
duk_context
*
cx
)
{
const
char
*
bind_name
=
NULL
;
...
...
@@ -452,7 +520,10 @@ int setup_js(void)
define_func
(
"exec"
,
js_mwexec
,
1
);
define_func
(
"say"
,
js_say
,
1
);
define_func
(
"wholist"
,
js_wholist
,
0
);
define_func
(
"rpc"
,
js_rpc
,
3
);
define_func
(
"ipc"
,
js_ipc
,
2
);
define_func
(
"beep"
,
js_beep
,
1
);
define_func
(
"termsize"
,
js_termsize
,
0
);
define_func
(
"bind"
,
js_bind
,
3
);
define_func
(
"unbind"
,
js_unbind
,
2
);
duk_pop
(
ctx
);
...
...
src/client/talker.c
View file @
7ee44b4e
...
...
@@ -1182,7 +1182,7 @@ void set_talk_rights(void)
current_rights
=
RIGHTS_TALK
;
}
void
sendipc
(
char
*
to
,
char
*
text
,
int
bcast
)
void
sendipc
(
const
char
*
to
,
const
char
*
text
,
int
bcast
)
{
int
count
;
...
...
@@ -1206,7 +1206,7 @@ void sendipc(char *to, char *text, int bcast)
}
}
void
sendrpc
(
char
*
to
,
char
*
type
,
char
*
text
,
int
bcast
)
void
sendrpc
(
const
char
*
to
,
const
char
*
type
,
const
char
*
text
,
int
bcast
)
{
char
buff
[
MAXTEXTLENGTH
];
int
count
;
...
...
src/client/talker.h
View file @
7ee44b4e
...
...
@@ -72,8 +72,8 @@ void enter_talker(int logontype);
int
screen_h
(
void
);
int
screen_w
(
void
);
void
sendipc
(
char
*
to
,
char
*
text
,
int
broadcast
);
void
sendrpc
(
char
*
to
,
char
*
type
,
char
*
text
,
int
broadcast
);
void
sendipc
(
const
char
*
to
,
const
char
*
text
,
int
broadcast
);
void
sendrpc
(
const
char
*
to
,
const
char
*
type
,
const
char
*
text
,
int
broadcast
);
int
ChangeRoom
(
char
*
room
,
int
quiet
);
void
enter_room
(
int
room
);
...
...