Added Difficulty rating to Sessions. Update time in real time. Fix "Loop

1".
This commit is contained in:
sigonasr2 2017-11-20 20:55:05 -06:00
parent 5978cf6e49
commit 87ab40209b
6 changed files with 101 additions and 22 deletions

Binary file not shown.

View File

@ -61,6 +61,10 @@ public class Profile {
this.parent = module; this.parent = module;
} }
public Profile getArchive() {
return oldProfile;
}
public void archiveAllValues() { public void archiveAllValues() {
oldProfile.healthUps = healthUps; oldProfile.healthUps = healthUps;
oldProfile.attackUps = attackUps; oldProfile.attackUps = attackUps;
@ -70,6 +74,7 @@ public class Profile {
oldProfile.rainbowEggCount = rainbowEggCount; oldProfile.rainbowEggCount = rainbowEggCount;
oldProfile.key_items = (HashMap<MemoryData, Integer>)key_items.clone(); oldProfile.key_items = (HashMap<MemoryData, Integer>)key_items.clone();
oldProfile.badges = (HashMap<MemoryData, Integer>)badges.clone(); oldProfile.badges = (HashMap<MemoryData, Integer>)badges.clone();
oldProfile.playtime = playtime;
} }
public void compareAndAnnounceAllChangedValues() { public void compareAndAnnounceAllChangedValues() {
@ -173,7 +178,7 @@ public class Profile {
} }
} }
public void downloadProfile() { public boolean downloadProfile() {
if (sigIRC.authenticated) { if (sigIRC.authenticated) {
File file = new File(sigIRC.BASEDIR+"tmp_profile"); File file = new File(sigIRC.BASEDIR+"tmp_profile");
try { try {
@ -223,8 +228,10 @@ public class Profile {
while (!nextval.equalsIgnoreCase("UPDATES:")); while (!nextval.equalsIgnoreCase("UPDATES:"));
} }
lastWebUpdate = System.currentTimeMillis(); lastWebUpdate = System.currentTimeMillis();
return true;
} }
} }
return false;
} }
private String getDataString() { private String getDataString() {
@ -319,9 +326,9 @@ public class Profile {
}; };
String diffstring = ""; String diffstring = "";
if (difficulty<difficulty_list.length) { if (difficulty<difficulty_list.length) {
diffstring = difficulty_list[difficulty]+((loop>0)?" Loop "+loop:""); diffstring = difficulty_list[difficulty]+((loop>1)?" Loop "+loop:"");
} else { } else {
diffstring = difficulty_list[difficulty_list.length-1]+((loop>0)?" Loop "+loop:""); diffstring = difficulty_list[difficulty_list.length-1]+((loop>1)?" Loop "+loop:"");
} }
return diffstring; return diffstring;
} }

View File

@ -14,6 +14,7 @@ public class Session {
String name = ""; String name = "";
int maxPlayers = 0; int maxPlayers = 0;
String password = ""; String password = "";
float difficulty = -1;
int id = 0; int id = 0;
List<Profile> players = new ArrayList<Profile>(); List<Profile> players = new ArrayList<Profile>();
@ -32,31 +33,36 @@ public class Session {
if (split.length>=7) { if (split.length>=7) {
String val = split[i++]; String val = split[i++];
String[] playerlist = val.split(";"); String[] playerlist = val.split(";");
//System.out.println(Arrays.toString(playerlist)); System.out.println(Arrays.toString(playerlist));
if (playerlist.length>0) { if (playerlist.length>1) {
for (String s : playerlist) { for (String s : playerlist) {
Profile p = new Profile(RabiRaceModule.module,true); Profile p = new Profile(RabiRaceModule.module,true);
p.username=s; p.username=s;
//System.out.println("Player "+p.username); //System.out.println("Player "+p.username);
p.downloadProfile(); if (p.downloadProfile()) {
if (RabiRaceModule.mySession==null && p.username.equalsIgnoreCase(RabiRaceModule.module.myProfile.username)) {
RabiRaceModule.mySession = this;
}
//System.out.println("Adding Player "+p);
players.add(p);
}
}
} else {
Profile p = new Profile(RabiRaceModule.module,true);
p.username=val;
//System.out.println("Player "+p.username);
if (p.downloadProfile()) {
if (RabiRaceModule.mySession==null && p.username.equalsIgnoreCase(RabiRaceModule.module.myProfile.username)) { if (RabiRaceModule.mySession==null && p.username.equalsIgnoreCase(RabiRaceModule.module.myProfile.username)) {
RabiRaceModule.mySession = this; RabiRaceModule.mySession = this;
} }
//System.out.println("Adding Player "+p); //System.out.println("Adding Player "+p);
players.add(p); players.add(p);
} }
} else {
Profile p = new Profile(RabiRaceModule.module,true);
p.username=val;
//System.out.println("Player "+p.username);
p.downloadProfile();
if (RabiRaceModule.mySession==null && p.username.equalsIgnoreCase(RabiRaceModule.module.myProfile.username)) {
RabiRaceModule.mySession = this;
}
//System.out.println("Adding Player "+p);
players.add(p);
} }
} }
if (split.length>=8) {
difficulty = Float.parseFloat(split[i++]);
}
} }
public int getID() { public int getID() {

View File

@ -30,6 +30,7 @@ public class SessionCreateWindow extends JFrame{
JPanel container = new JPanel(); JPanel container = new JPanel();
LengthValidationField session_name = new LengthValidationField(16); LengthValidationField session_name = new LengthValidationField(16);
NumberValidationField maxplayers = new NumberValidationField(); NumberValidationField maxplayers = new NumberValidationField();
FloatValidationField difficulty = new FloatValidationField();
JPasswordField pass = new JPasswordField(); JPasswordField pass = new JPasswordField();
JButton create = new JButton("Create"); JButton create = new JButton("Create");
@ -40,9 +41,10 @@ public class SessionCreateWindow extends JFrame{
JPanel namepanel = new JPanel(); JPanel namepanel = new JPanel();
JPanel playerpanel = new JPanel(); JPanel playerpanel = new JPanel();
JPanel passwordpanel = new JPanel(); JPanel passwordpanel = new JPanel();
JPanel difficultypanel = new JPanel();
JPanel[] panel_list = new JPanel[]{ JPanel[] panel_list = new JPanel[]{
namepanel,playerpanel,passwordpanel namepanel,playerpanel,passwordpanel,difficultypanel
}; };
for (JPanel panel : panel_list) { for (JPanel panel : panel_list) {
@ -73,6 +75,13 @@ public class SessionCreateWindow extends JFrame{
playerpanel.add(passwordLabel); playerpanel.add(passwordLabel);
playerpanel.add(pass); playerpanel.add(pass);
JLabel difficultyLabel = new JLabel("Race Difficulty (0.00~10.00): ");
difficulty.setPreferredSize(new Dimension(60,24));
difficulty.setText("5.00");
difficultypanel.add(difficultyLabel);
difficultypanel.add(difficulty);
for (JPanel panel : panel_list) { for (JPanel panel : panel_list) {
panel.add(Box.createRigidArea(new Dimension(24,24))); panel.add(Box.createRigidArea(new Dimension(24,24)));
} }
@ -102,6 +111,10 @@ public class SessionCreateWindow extends JFrame{
JOptionPane.showMessageDialog(RabiRaceModule.createwindow, "Your max player count needs to be between 2-48!", "Error!", JOptionPane.WARNING_MESSAGE); JOptionPane.showMessageDialog(RabiRaceModule.createwindow, "Your max player count needs to be between 2-48!", "Error!", JOptionPane.WARNING_MESSAGE);
return; return;
} }
if (!TextUtils.isNumeric(difficulty.getText()) && difficulty.getText().length()>0) {
JOptionPane.showMessageDialog(RabiRaceModule.createwindow, "Your difficulty value is invalid! (A number between 0.00 and 10.00)", "Error!", JOptionPane.WARNING_MESSAGE);
return;
}
String hashpass = ""; String hashpass = "";
if (String.copyValueOf(pass.getPassword()).length()>0) { if (String.copyValueOf(pass.getPassword()).length()>0) {
hashpass = SessionListWindow.GetHashedPassword(String.copyValueOf(pass.getPassword())); hashpass = SessionListWindow.GetHashedPassword(String.copyValueOf(pass.getPassword()));
@ -109,7 +122,8 @@ public class SessionCreateWindow extends JFrame{
session_name.setText(session_name.getText().replaceAll(" ", "%20")); session_name.setText(session_name.getText().replaceAll(" ", "%20"));
File file = new File(sigIRC.BASEDIR+"sigIRC/tmp.data"); File file = new File(sigIRC.BASEDIR+"sigIRC/tmp.data");
try { try {
org.apache.commons.io.FileUtils.copyURLToFile(new URL("http://45.33.13.215/rabirace/send.php?key=sessioncreate&name="+session_name.getText()+"&players="+maxplayers.getText()+"&password="+((hashpass.length()>0)?hashpass:"none")),file); org.apache.commons.io.FileUtils.copyURLToFile(new URL("http://45.33.13.215/rabirace/send.php?key=sessioncreate&name="+session_name.getText()+"&players="+maxplayers.getText()+"&password="+((hashpass.length()>0)?hashpass:"none")+"&difficulty="+((difficulty.getText().length()>0)?difficulty.getText():"-1")),file);
//org.apache.commons.io.FileUtils.copyURLToFile(new URL("http://45.33.13.215/rabirace/send.php?key=sessioncreate&name="+session_name.getText()+"&players="+maxplayers.getText()+"&password="+((hashpass.length()>0)?hashpass:"none")),file);
String[] contents = FileUtils.readFromFile(sigIRC.BASEDIR+"sigIRC/tmp.data"); String[] contents = FileUtils.readFromFile(sigIRC.BASEDIR+"sigIRC/tmp.data");
int sessionID=-1; int sessionID=-1;
if (contents.length>=2) { if (contents.length>=2) {
@ -139,6 +153,7 @@ public class SessionCreateWindow extends JFrame{
container.add(namepanel); container.add(namepanel);
container.add(playerpanel); container.add(playerpanel);
container.add(passwordpanel); container.add(passwordpanel);
container.add(difficultypanel);
container.add(create); container.add(create);
container.add(Box.createRigidArea(new Dimension(24,24))); container.add(Box.createRigidArea(new Dimension(24,24)));
@ -223,4 +238,46 @@ public class SessionCreateWindow extends JFrame{
return false; return false;
} }
} }
class FloatValidationField extends JTextField implements DocumentListener{
public FloatValidationField() {
getDocument().addDocumentListener(this);
}
@Override
public void changedUpdate(DocumentEvent arg0) {
}
@Override
public void insertUpdate(DocumentEvent arg0) {
ValidateForm();
}
protected void ValidateForm() {
if (fieldIsInvalid()) {
setBackground(Color.RED);
} else {
setBackground(Color.WHITE);
}
}
@Override
public void removeUpdate(DocumentEvent arg0) {
ValidateForm();
}
protected boolean fieldIsInvalid() {
if (!TextUtils.isNumeric(getText()) && getText().length()>0) {
return true;
}
if (TextUtils.isNumeric(getText()) && getText().length()>0) {
float val = Float.parseFloat(getText());
if (val>10f || val<0f) {
return true;
}
}
return false;
}
}
} }

View File

@ -9,6 +9,7 @@ import java.io.IOException;
import java.net.URL; import java.net.URL;
import java.security.MessageDigest; import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import java.text.DecimalFormat;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@ -43,6 +44,7 @@ public class SessionListWindow extends JFrame{
public JScrollPane scrolllist = new JScrollPane(); public JScrollPane scrolllist = new JScrollPane();
public PasswordBox box = new PasswordBox(); public PasswordBox box = new PasswordBox();
public String enteredPassword = ""; public String enteredPassword = "";
DecimalFormat df = new DecimalFormat("0.00");
public SessionListWindow(){ public SessionListWindow(){
@ -52,8 +54,8 @@ public class SessionListWindow extends JFrame{
previewPanel.setWindow(this); previewPanel.setWindow(this);
scrolllist.setViewportView(sessionlist); scrolllist.setViewportView(sessionlist);
scrolllist.setPreferredSize(new Dimension(160,150)); scrolllist.setPreferredSize(new Dimension(272,150));
scrolllist.setMinimumSize(new Dimension(160,150)); scrolllist.setMinimumSize(new Dimension(272,150));
scrolllist.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); scrolllist.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
JPanel sessionPanel = new JPanel(); JPanel sessionPanel = new JPanel();
@ -137,7 +139,7 @@ public class SessionListWindow extends JFrame{
this.add(container); this.add(container);
this.setMinimumSize(new Dimension(640,480)); this.setMinimumSize(new Dimension(720,480));
} }
public static void ConnectToSession(Session session, String hashedPass) { public static void ConnectToSession(Session session, String hashedPass) {
@ -200,7 +202,7 @@ public class SessionListWindow extends JFrame{
int count=0; int count=0;
for (Integer id : RabiRaceModule.module.session_listing.data.keySet()) { for (Integer id : RabiRaceModule.module.session_listing.data.keySet()) {
Session session = RabiRaceModule.module.session_listing.data.get(id); Session session = RabiRaceModule.module.session_listing.data.get(id);
sessionlist_model.addElement((session.password.equalsIgnoreCase("none")?"":"🔑 ")+session.id+" - "+session.name+" ("+session.players.size()+"/"+session.maxPlayers+")"); sessionlist_model.addElement((session.password.equalsIgnoreCase("none")?"":"🔑 ")+session.id+" - "+session.name+" ("+session.players.size()+"/"+session.maxPlayers+")"+((session.difficulty!=-1)?" - Rating: "+df.format(session.difficulty):""));
if (id == selectedID && sessionlist_model.getSize()>count) { if (id == selectedID && sessionlist_model.getSize()>count) {
sessionlist.setSelectedIndex(count); sessionlist.setSelectedIndex(count);
} }

View File

@ -295,6 +295,13 @@ public class RabiRaceModule extends Module{
} }
firstUpdate=false; firstUpdate=false;
} }
for (Profile p : mySession.getPlayers()) {
if (!p.username.equalsIgnoreCase(myProfile.username)) {
if (!p.isPaused) {
p.playtime += myProfile.playtime-myProfile.getArchive().playtime;
}
}
}
} }
} }