Spikesscape
Would you like to react to this message? Create an account in a few clicks or log in to continue.

[508]Pm/ignore/Freinds

2 posters

Go down

[508]Pm/ignore/Freinds Empty [508]Pm/ignore/Freinds

Post  [Owner]Spikes Sun Aug 23, 2009 6:11 am

Description: Addings friends/ignores/pming to Paladino76's non-NIO server.

Difficulty: 5, you need to know how to add code in a place without guidance of where exactly it should go, need to know how to add imports.

Assumed Knowledge: Brain.

Tested Server: Paladino76's non-NIO 508: compatible with Espeon and NIO with changes.

Files/Classes Modified: Frames, Login, FileManager, Player, PacketManager, Packets

Procedure

If you have problems with saving or loading, you've done something wrong.

Alright I'll make this as short as possible Razz.

First we need to add the frames:

Code:

public void connecttofserver(Player p){
if(p == null || p.stream == null || p.disconnected[0]){
return;
}
p.stream.createFrame(115);
p.stream.writeByte(2);
}

public void sendSentPrivateMessage(Player p, long name, String message) {
byte[] bytes = new byte[message.length()];
Misc.encryptPlayerChat(bytes, 0, 0, message.length(), message.getBytes());
p.stream.createFrameVarSize(89);
p.stream.writeQWord(name);
p.stream.writeByte(message.length());
p.stream.writeBytes(bytes, bytes.length, 0);
p.stream.endFrameVarSize();
}

private static int messageCounter = 1;
public void sendReceivedPrivateMessage(Player p, long name, int rights, String message) {
int id = messageCounter++;
if(id > 16000000) {
id = 1;
}
byte[] bytes = new byte[message.length()+1];
bytes[0] = (byte) message.length();
Misc.encryptPlayerChat(bytes, 0, 1, message.length(), message.getBytes());
p.stream.createFrameVarSize(178);
p.stream.writeQWord(name);
p.stream.writeWord(1);
p.stream.writeByte(((id << 16) & 0xFF));
p.stream.writeByte(((id << 8 ) & 0xFF));
p.stream.writeByte(((id ) & 0xFF));
p.stream.writeByte(rights);
p.stream.writeBytes(bytes, bytes.length, 0);
p.stream.endFrameVarSize();
}

public void sendFriend(Player p, long name, int world) {
p.stream.createFrameVarSize(154);
p.stream.writeQWord(name);
p.stream.writeWord(world);
p.stream.writeByte(1);
if(world != 0) {
if(world == 66) {
p.stream.writeString("Online");
} else {
p.stream.writeString("RuneScape " + world);
}
}
p.stream.endFrameVarSize();
}

public void sendIgnores(Player p, long[] ignores) {
p.stream.createFrameVarSizeWord(240);
for(long ignore : ignores) {
p.stream.writeQWord(ignore);
}
p.stream.endFrameVarSizeWord();
}

You may already have connecttofserver.

Now we go to Login.java:

Under:

p.playerWeapon.setWeapon();

Add:

p.frames.connecttofserver(p);

And then:

p.friendsLoggedIn();

That method will be used to update friends when we make it.

We also need a corresponding logout method. We'll call that in their destruct() method.

Add imports:

import java.util.*;
import java.lang.*;

Add these lists into the Player class:

public List<Long> friends = new ArrayList<Long>(200);
public List<Long> ignores = new ArrayList<Long>(100);

Also add these methods:

Code:

public void friendsLoggedIn() {
for(Long friend : friends) {
frames.sendFriend(this, friend, getWorld(friend));
}
long[] array = new long[ignores.size()];
int i = 0;
for(Long ignore : ignores) {
if(ignore != null)
array[i++] = ignore;
}
frames.sendIgnores(this, array);
long me = Misc.stringToLong(username);
for(Player p : Engine.players) {
if(p == null) continue;
if(p.friends.contains(me)) {
p.frames.sendFriend(p, me, 66);
}
}
}
public int getWorld(long friend) {
for(Player p : Engine.players) {
if(p != null && p.online) {
if(Misc.stringToLong(p.username) == friend) {
return 66;
}
}
}
return 0;
}

Finally in destruct method add:

Code:

long me = Misc.stringToLong(username);
for(Player p : Engine.players) {
if(p == null) continue;
if(p.friends.contains(me)) {
p.frames.sendFriend(p, me, 0);
}
}

In Packets.java

set: 30, 61, 132, 2 to size 8, 178 to size -1.

Now in PacketManager add this:

Code:

case 30:
long name = p.stream.readQWord();
if(p.friends.size() >= 200) {
p.frames.sendMessage(p, "Your friends list is full.");
break;
}
if(p.friends.contains((Long) name)) {
p.frames.sendMessage(p, "Already on your friends list.");
break;
}
p.friends.add((Long) name);
p.frames.sendFriend(p, name, p.getWorld(name));
break;
case 61:
name = p.stream.readQWord();
if(p.ignores.size() >= 100) {
p.frames.sendMessage(p, "Your ignore list is full.");
break;
}
if(p.ignores.contains((Long) name)) {
p.frames.sendMessage(p, "Already on your ignore list.");
break;
}
p.ignores.add((Long) name);
break;
case 132:
name = p.stream.readQWord();
p.friends.remove((Long) name);
break;
case 2:
name = p.stream.readQWord();
p.ignores.remove((Long) name);
break;
case 178:
name = p.stream.readQWord();
int numChars = p.stream.readUnsignedByte();
String text = Misc.decryptPlayerChat(p.stream, numChars);
for(Player p2 : Engine.players) {
if(p2 != null && p2.online) {
if(Misc.stringToLong(p2.username) == name) {
p2.frames.sendReceivedPrivateMessage(p2, Misc.stringToLong(p.username), p.rights, text);
p.frames.sendSentPrivateMessage(p, name, text);
return;
}
}
}
p.frames.sendMessage(p, "Player is unavailable.");
break;

Nearly there! Just the save/load code left - then we're done .

So in the FileManager class, before stream.writeString("null") add:

Code:

for (int i = 0; i < 200; i++) {
if (i < p.friends.size()) {
stream.writeString("friend" + i + ":" + p.friends.get(i));
}
}
for (int i = 0; i < 100; i++) {
if (i < p.ignores.size()) {
stream.writeString("ignores" + i + ":" + p.ignores.get(i));
}
}

And then:

Code:

} else if(line.startsWith("friend")) {
long friendName = Long.parseLong(line.substring(line.indexOf(":")+1));
p.friends.add(friendName);
} else if(line.startsWith("ignore")) {
long ignoreName = Long.parseLong(line.substring(line.indexOf(":")+1));
p.ignores.add(ignoreName);
}

With the saving code.

Credits: Graham
[Owner]Spikes
[Owner]Spikes
Admin

Posts : 28
Join date : 2009-08-22

https://spikesscape.forumotion.com

Back to top Go down

[508]Pm/ignore/Freinds Empty Re: [508]Pm/ignore/Freinds

Post  Zamorak Mon Aug 24, 2009 8:38 am

Nice,I mean nice graham! Umm...Whos graham?

Zamorak
Admin

Posts : 38
Join date : 2009-08-23
Age : 34
Location : England

http://green-knight.webs.com

Back to top Go down

[508]Pm/ignore/Freinds Empty Re: [508]Pm/ignore/Freinds

Post  [Owner]Spikes Mon Aug 24, 2009 3:47 pm

idk! XD
[Owner]Spikes
[Owner]Spikes
Admin

Posts : 28
Join date : 2009-08-22

https://spikesscape.forumotion.com

Back to top Go down

[508]Pm/ignore/Freinds Empty Re: [508]Pm/ignore/Freinds

Post  Zamorak Tue Aug 25, 2009 7:51 am

Lol Ur funny.

Zamorak
Admin

Posts : 38
Join date : 2009-08-23
Age : 34
Location : England

http://green-knight.webs.com

Back to top Go down

[508]Pm/ignore/Freinds Empty Re: [508]Pm/ignore/Freinds

Post  Sponsored content


Sponsored content


Back to top Go down

Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum