Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Synchronet
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Main
Synchronet
Commits
acebf51e
Commit
acebf51e
authored
7 years ago
by
rswindell
Browse files
Options
Downloads
Patches
Plain Diff
Library to deal with Avatars (import/export/draw)
parent
866824cf
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
exec/load/avatar_lib.js
+152
-0
152 additions, 0 deletions
exec/load/avatar_lib.js
with
152 additions
and
0 deletions
exec/load/avatar_lib.js
0 → 100644
+
152
−
0
View file @
acebf51e
// $Id$
// Library for dealing with user Avatars (ex-ASCII/ANSI block art)
const
defs
=
{
width
:
10
,
height
:
6
,
};
function
local_fname
(
usernum
)
{
return
format
(
"
%suser/%04u.ini
"
,
system
.
data_dir
,
usernum
);
}
function
qnet_fname
(
netaddr
)
{
return
format
(
"
%sqnet/%s.avatars.ini
"
,
system
.
data_dir
,
file_getname
(
netaddr
));
}
function
write_local
(
usernum
,
obj
)
{
var
file
=
new
File
(
this
.
local_fname
(
usernum
));
if
(
!
file
.
open
(
file
.
exists
?
'
r+
'
:
'
w+
'
))
{
return
false
;
}
var
result
=
file
.
iniSetObject
(
"
avatar
"
,
obj
);
file
.
close
();
return
result
;
}
function
write_qnet
(
username
,
netaddr
,
obj
)
{
var
file
=
new
File
(
this
.
qnet_fname
(
netaddr
));
if
(
!
file
.
open
(
file
.
exists
?
'
r+
'
:
'
w+
'
))
{
return
false
;
}
var
result
=
file
.
iniSetObject
(
username
,
obj
);
file
.
close
();
return
result
;
}
function
read_local
(
usernum
)
{
var
file
=
new
File
(
this
.
local_fname
(
usernum
));
if
(
!
file
.
open
(
"
r
"
))
{
return
false
;
}
var
obj
=
file
.
iniGetObject
(
"
avatar
"
);
file
.
close
();
return
obj
;
}
function
read_qnet
(
username
,
netaddr
)
{
var
file
=
new
File
(
this
.
qnet_fname
(
netaddr
));
if
(
!
file
.
open
(
"
r
"
))
{
return
false
;
}
var
obj
=
file
.
iniGetObject
(
username
);
file
.
close
();
return
obj
;
}
function
read
(
usernum
,
username
,
netaddr
)
{
if
(
parseInt
(
usernum
)
>=
1
)
return
read_local
(
usernum
);
else
return
read_qnet
(
username
,
netaddr
);
}
function
update_local
(
usernum
,
data
)
{
var
obj
=
read_local
(
usernum
);
if
(
obj
==
false
)
obj
=
{
created
:
new
Date
()
};
obj
.
data
=
data
;
obj
.
updated
=
new
Date
();
return
write_local
(
usernum
,
obj
);
}
function
import_file
(
usernum
,
filename
,
offset
)
{
load
(
'
graphic.js
'
);
var
graphic
=
new
Graphic
(
this
.
defs
.
width
,
this
.
defs
.
height
);
if
(
!
graphic
.
load
(
filename
,
offset
))
return
false
;
return
update_local
(
usernum
,
base64_encode
(
graphic
.
BIN
));
}
function
find_name
(
objs
,
name
)
{
for
(
var
i
=
0
;
i
<
objs
.
length
;
i
++
)
if
(
objs
[
i
].
name
.
toLowerCase
()
==
name
.
toLowerCase
())
return
i
;
return
-
1
;
}
function
import_list
(
netaddr
,
list
)
{
var
objs
=
[];
var
file
=
new
File
(
this
.
qnet_fname
(
netaddr
));
if
(
file
.
open
(
"
r
"
))
{
objs
=
file
.
iniGetAllObjects
();
file
.
close
();
}
for
(
var
i
in
list
)
{
for
(
var
u
in
list
[
i
])
{
var
index
=
find_name
(
objs
,
list
[
i
][
u
]);
if
(
index
>=
0
)
{
if
(
objs
[
index
].
data
!=
i
)
{
objs
[
index
].
data
=
i
;
objs
[
index
].
updated
=
new
Date
();
}
}
else
objs
.
push
({
name
:
list
[
i
][
u
],
data
:
i
,
created
:
new
Date
()
});
}
}
if
(
!
file
.
open
(
"
w
"
))
return
false
;
var
result
=
file
.
iniSetAllObjects
(
objs
);
file
.
close
();
return
result
;
}
function
draw
(
usernum
,
username
,
netaddr
,
above
,
right
)
{
var
avatar
=
this
.
read
(
usernum
,
username
,
netaddr
);
if
(
avatar
)
{
load
(
'
graphic.js
'
);
var
graphic
=
new
Graphic
(
this
.
defs
.
width
,
this
.
defs
.
height
);
try
{
graphic
.
BIN
=
base64_decode
([
avatar
.
data
]);
var
lncntr
=
console
.
line_counter
;
var
pos
=
console
.
getxy
();
var
x
=
pos
.
x
;
var
y
=
pos
.
y
;
if
(
above
)
y
-=
this
.
defs
.
height
;
if
(
right
)
x
=
console
.
screen_columns
-
(
this
.
defs
.
width
+
1
);
graphic
.
attr_mask
=
~
graphic
.
defs
.
BLINK
;
// Disable blink attribute (consider iCE colors?)
graphic
.
draw
(
x
,
y
,
this
.
defs
.
width
,
this
.
defs
.
height
);
console
.
gotoxy
(
pos
);
console
.
line_counter
=
lncntr
;
}
catch
(
e
)
{
};
}
}
this
;
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment