Skip to content

Commit b9ca882

Browse files
committed
Server v.: 0.1
Initial server release with structure for interaction
0 parents  commit b9ca882

File tree

7 files changed

+125
-0
lines changed

7 files changed

+125
-0
lines changed

‎.gitignore‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Eclipse
2+
.classpath
3+
.project
4+
.settings/
5+
.metadata
6+
7+
# Mac
8+
.DS_Store
9+
10+
# Java
11+
/bin/
12+
*.jar

‎BServer/.gitignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/bin
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package com.github.neverbolt.bserver;
2+
3+
import java.io.BufferedReader;
4+
import java.io.IOException;
5+
import java.io.InputStreamReader;
6+
7+
import com.github.neverbolt.bserver.commands.CommandHandler;
8+
9+
public class InputHandler {
10+
private BufferedReader clIn;
11+
private CommandHandler commands;
12+
13+
public InputHandler() {
14+
clIn = new BufferedReader(new InputStreamReader(System.in));
15+
commands = new CommandHandler();
16+
}
17+
18+
public void run() {
19+
String temp;
20+
System.out.print("> ");
21+
while(!(temp = readLine()).toLowerCase().equals("exit")) {
22+
execute(temp);
23+
24+
System.out.print("> ");
25+
}
26+
27+
System.out.println("Shutting down!");
28+
}
29+
30+
public String readLine() {
31+
String temp = null;
32+
try {
33+
temp = clIn.readLine();
34+
} catch (IOException e) {
35+
System.out.println("There has been an error with your command");
36+
}
37+
return temp;
38+
}
39+
40+
private void execute(String input) {
41+
commands.run(input);
42+
}
43+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.github.neverbolt.bserver;
2+
3+
4+
public class Main {
5+
/**
6+
*
7+
* @param args
8+
*/
9+
public static void main(String[] args) {
10+
InputHandler ih = new InputHandler();
11+
12+
ih.run();
13+
}
14+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.github.neverbolt.bserver.commands;
2+
3+
public interface Command {
4+
public void run(String... params);
5+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package com.github.neverbolt.bserver.commands;
2+
3+
import java.util.HashMap;
4+
5+
public class CommandHandler {
6+
private HashMap<String, Command> commands;
7+
8+
/**
9+
* Initialize the command list
10+
*/
11+
public CommandHandler() {
12+
commands = new HashMap<String, Command>();
13+
commands.put("select", new Select());
14+
}
15+
16+
public void run(String input) {
17+
String[] parts = input.split(" ");
18+
// Check if any parameter has been passed at all
19+
if(parts.length>=1&&!input.trim().isEmpty()) {
20+
// Check for if the command exists
21+
if(commands.containsKey(parts[0].toLowerCase())) {
22+
// Fetch the command and execute
23+
commands.get(parts[0].toLowerCase()).run(parts);
24+
} else {
25+
System.out.println(parts[0] + ": command not found");
26+
}
27+
}
28+
}
29+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.github.neverbolt.bserver.commands;
2+
3+
/**
4+
*
5+
* @author Neverbolt
6+
* @version 0.1
7+
*
8+
* Select one or more bots via flags or ID's
9+
*/
10+
public class Select implements Command {
11+
12+
@Override
13+
public void run(String... params) {
14+
if(params.length<2||params.length>3) {
15+
System.out.println("usage: select [-flag | -id] selector ...");
16+
return;
17+
}
18+
19+
System.out.println(params.length-1);
20+
}
21+
}

0 commit comments

Comments
 (0)