Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
M
Mirai
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MyCard
Mirai
Commits
1ac45fa7
Commit
1ac45fa7
authored
Aug 17, 2019
by
liujiahua123123
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test
parent
325110e9
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
16 additions
and
248 deletions
+16
-248
mirai-core/src/main/java/net/mamoe/mirai/utils/config/MiraiConfig.java
...c/main/java/net/mamoe/mirai/utils/config/MiraiConfig.java
+0
-96
mirai-core/src/main/java/net/mamoe/mirai/utils/config/MiraiConfigSection.java
...java/net/mamoe/mirai/utils/config/MiraiConfigSection.java
+0
-12
mirai-core/src/main/java/net/mamoe/mirai/utils/config/MiraiListSection.java
...n/java/net/mamoe/mirai/utils/config/MiraiListSection.java
+0
-52
mirai-core/src/main/java/net/mamoe/mirai/utils/config/MiraiMapSection.java
...in/java/net/mamoe/mirai/utils/config/MiraiMapSection.java
+0
-88
mirai-core/src/test/java/NetworkTest.java
mirai-core/src/test/java/NetworkTest.java
+10
-0
mirai-core/src/test/java/PacketTest.kt
mirai-core/src/test/java/PacketTest.kt
+6
-0
No files found.
mirai-core/src/main/java/net/mamoe/mirai/utils/config/MiraiConfig.java
deleted
100644 → 0
View file @
325110e9
package
net.mamoe.mirai.utils.config
;
import
org.ini4j.Config
;
import
org.ini4j.Ini
;
import
org.ini4j.Profile
;
import
java.io.File
;
import
java.io.IOException
;
import
java.net.URL
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Vector
;
import
java.util.concurrent.ConcurrentHashMap
;
/**
* Mirai Config
* Only support {INI} format
* Support MAP and LIST
* Thread safe
*/
public
class
MiraiConfig
{
private
File
file
;
private
Ini
ini
;
private
volatile
Map
<
String
,
MiraiConfigSection
>
cacheSection
=
new
ConcurrentHashMap
<>();
public
MiraiConfig
(
File
file
){
if
(!
file
.
getName
().
contains
(
"."
)){
file
=
new
File
(
file
.
getParent
()
+
file
.
getName
()
+
".ini"
);
}
this
.
file
=
file
;
try
{
if
(
file
.
exists
()){
file
.
createNewFile
();
}
Config
config
=
new
Config
();
config
.
setMultiSection
(
true
);
ini
=
new
Ini
();
ini
.
setConfig
(
config
);
ini
.
load
(
this
.
file
.
toURI
().
toURL
());
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
public
void
setSection
(
String
key
,
MiraiConfigSection
section
){
cacheSection
.
put
(
key
,
section
);
}
public
MiraiMapSection
getMapSection
(
String
key
){
if
(!
cacheSection
.
containsKey
(
key
))
{
MiraiMapSection
section
=
new
MiraiMapSection
();
if
(
ini
.
containsKey
(
key
)){
section
.
putAll
(
ini
.
get
(
key
));
}
cacheSection
.
put
(
key
,
section
);
}
return
(
MiraiMapSection
)
cacheSection
.
get
(
key
);
}
public
MiraiListSection
getListSection
(
String
key
){
if
(!
cacheSection
.
containsKey
(
key
))
{
MiraiListSection
section
=
new
MiraiListSection
();
if
(
ini
.
containsKey
(
key
)){
section
.
addAll
(
ini
.
get
(
key
).
values
());
}
cacheSection
.
put
(
key
,
section
);
}
return
(
MiraiListSection
)
cacheSection
.
get
(
key
);
}
public
synchronized
void
save
(){
cacheSection
.
forEach
((
k
,
a
)
->
{
if
(!
ini
.
containsKey
(
k
))
{
ini
.
put
(
k
,
""
,
new
HashMap
<>());
}
a
.
saveAsSection
(
ini
.
get
(
k
));
});
this
.
clearCache
();
try
{
ini
.
store
(
file
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
public
void
clearCache
(){
cacheSection
.
clear
();
}
}
mirai-core/src/main/java/net/mamoe/mirai/utils/config/MiraiConfigSection.java
deleted
100644 → 0
View file @
325110e9
package
net.mamoe.mirai.utils.config
;
import
org.ini4j.Profile
;
import
java.io.Closeable
;
import
java.util.Map
;
public
interface
MiraiConfigSection
extends
Closeable
{
void
saveAsSection
(
Profile
.
Section
section
);
}
mirai-core/src/main/java/net/mamoe/mirai/utils/config/MiraiListSection.java
deleted
100644 → 0
View file @
325110e9
package
net.mamoe.mirai.utils.config
;
import
org.ini4j.Profile
;
import
java.io.IOException
;
import
java.util.Map
;
import
java.util.Vector
;
import
java.util.concurrent.atomic.AtomicInteger
;
import
java.util.concurrent.locks.Lock
;
import
java.util.concurrent.locks.ReentrantLock
;
public
class
MiraiListSection
extends
Vector
<
Object
>
implements
MiraiConfigSection
{
private
Lock
lock
=
new
ReentrantLock
();
@SuppressWarnings
(
"unchecked"
)
public
<
T
>
T
getAs
(
int
index
){
return
(
T
)
super
.
get
(
index
);
}
public
int
getInt
(
int
index
){
return
this
.
getAs
(
index
);
}
public
int
getDouble
(
int
index
){
return
this
.
getAs
(
index
);
}
public
int
getString
(
int
index
){
return
this
.
getAs
(
index
);
}
public
int
getFloat
(
int
index
)
{
return
this
.
getAs
(
index
);
}
@Override
public
synchronized
void
saveAsSection
(
Profile
.
Section
section
)
{
section
.
clear
();
AtomicInteger
integer
=
new
AtomicInteger
(
0
);
this
.
forEach
(
a
->
{
section
.
put
(
String
.
valueOf
(
integer
.
getAndAdd
(
1
)),
a
);
});
}
@Override
public
void
close
()
throws
IOException
{
}
}
mirai-core/src/main/java/net/mamoe/mirai/utils/config/MiraiMapSection.java
deleted
100644 → 0
View file @
325110e9
package
net.mamoe.mirai.utils.config
;
import
org.ini4j.Profile
;
import
java.io.IOException
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.concurrent.ConcurrentHashMap
;
import
java.util.concurrent.atomic.AtomicInteger
;
import
java.util.stream.Collectors
;
public
class
MiraiMapSection
extends
ConcurrentHashMap
<
String
,
Object
>
implements
MiraiConfigSection
{
public
Object
get
(
String
key
){
return
this
.
get
(
key
,
null
);
}
@SuppressWarnings
(
"unchecked"
)
public
<
T
>
T
get
(
String
key
,
T
defaultValue
)
{
if
(
key
==
null
||
key
.
isEmpty
()){
return
defaultValue
;
}
if
(
super
.
containsKey
(
key
)){
return
(
T
)
super
.
get
(
key
);
}
return
defaultValue
;
}
public
void
set
(
String
key
,
Object
value
){
this
.
put
(
key
,
value
);
}
public
void
remove
(
String
key
){
super
.
remove
(
key
);
}
public
int
getInt
(
String
key
)
{
return
this
.
getInt
(
key
,
0
);
}
public
int
getInt
(
String
key
,
int
defaultValue
)
{
return
Integer
.
parseInt
(
String
.
valueOf
(
this
.
get
(
key
,
defaultValue
)));
}
public
double
getDouble
(
String
key
)
{
return
this
.
getDouble
(
key
,
0
D
);
}
public
double
getDouble
(
String
key
,
double
defaultValue
)
{
return
Double
.
parseDouble
(
String
.
valueOf
(
this
.
get
(
key
,
defaultValue
)));
}
public
float
getFloat
(
String
key
)
{
return
this
.
getFloat
(
key
,
0
F
);
}
public
float
getFloat
(
String
key
,
float
defaultValue
)
{
return
Float
.
parseFloat
(
String
.
valueOf
(
this
.
get
(
key
,
defaultValue
)));
}
public
String
getString
(
String
key
)
{
return
this
.
getString
(
key
,
""
);
}
public
String
getString
(
String
key
,
String
defaultValue
)
{
return
String
.
valueOf
(
this
.
get
(
key
,
defaultValue
));
}
@SuppressWarnings
(
"unchecked"
)
public
<
T
>
List
<
T
>
asList
(){
return
this
.
values
().
stream
().
map
(
a
->
(
T
)(
a
)).
collect
(
Collectors
.
toList
());
}
@Override
public
synchronized
void
saveAsSection
(
Profile
.
Section
section
)
{
section
.
clear
();
this
.
forEach
(
section:
:
put
);
}
@Override
public
void
close
()
throws
IOException
{
}
}
mirai-core/src/test/java/NetworkTest.java
View file @
1ac45fa7
import
net.mamoe.mirai.network.packet.server.Server0825Packet
;
import
java.io.ByteArrayInputStream
;
import
java.io.DataInputStream
;
import
java.io.InputStream
;
/**
* @author Him188moe @ Mirai Project
*/
public
class
NetworkTest
{
public
static
void
main
(
String
[]
args
)
{
/*
System.out.println(Short.valueOf("37 13", 16));
System.out.println(1040400290L & 0x0FFFFFFFF);
System.out.println(Long.valueOf("3E033FA2", 16));
*/
}
}
mirai-core/src/test/java/PacketTest.kt
0 → 100644
View file @
1ac45fa7
import
net.mamoe.mirai.network.packet.server.Server0825Packet
fun
main
(){
val
v
=
"00 37 13 08 25 31 01 76 E4 B8 DD 03 00 00 00 01 2E 01 00 00 68 52 00 00 00 00 A4 F1 91 88 C9 82 14 99 0C 9E 56 55 91 23 C8 3D C3 47 F0 25 A1 8E 74 EF 1E 0B 32 5B 20 8A FA 3B 0B 52 8F 86 E6 04 F1 D6 F8 63 75 60 8C 0C 7D 06 D1 E0 22 F8 49 EF AF 61 EE 7E 69 72 EB 10 08 30 69 50 1C 84 A9 C2 16 D7 52 B9 1C 79 CA 5A CF FD BC AE D8 A6 BB DC 21 6E 79 26 E1 A2 23 11 AA B0 9A 49 39 72 ED 61 12 B6 88 4D A2 56 23 E9 92 11 92 27 4A 70 00 C9 01 7B 03"
;
v
.
split
(
" "
)
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment