Source code: marauroa/net/MessageS2CCharacterList.java
1 /* $Id: MessageS2CCharacterList.java,v 1.2 2003/12/08 01:08:30 arianne_rpg Exp $ */
2 /***************************************************************************
3 * (C) Copyright 2003 - Marauroa *
4 ***************************************************************************
5 ***************************************************************************
6 * *
7 * This program is free software; you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation; either version 2 of the License, or *
10 * (at your option) any later version. *
11 * *
12 ***************************************************************************/
13 package marauroa.net;
14
15 import java.net.InetSocketAddress;
16 import java.io.*;
17
18 /** The CharacterListMessage is sent from server to client to inform client about
19 * the possible election of character to play with.*/
20 public class MessageS2CCharacterList extends Message
21 {
22 private String[] characters;
23
24 /** Constructor for allowing creation of an empty message */
25 public MessageS2CCharacterList()
26 {
27 super(null);
28
29 type=TYPE_S2C_CHARACTERLIST;
30 }
31
32 /** Constructor with a TCP/IP source/destination of the message and the name
33 * of the choosen character.
34 * @param source The TCP/IP address associated to this message
35 * @param characters the list of characters of the player
36 * @see marauroa.net.MessageS2CCharacters
37 */
38 public MessageS2CCharacterList(InetSocketAddress source,String[] characters)
39 {
40 super(source);
41
42 type=TYPE_S2C_CHARACTERLIST;
43 this.characters=characters;
44 }
45
46 /** This method returns the list of characters that the player owns
47 * @return the list of characters that the player owns */
48 public String[] getCharacters()
49 {
50 return characters;
51 }
52
53 /** This method returns a String that represent the object
54 * @return a string representing the object.*/
55 public String toString()
56 {
57 StringBuffer text=new StringBuffer(" ");
58 for(int i=0;i<characters.length;++i)
59 {
60 text.append(characters[i]+",");
61 }
62
63 return "Message (S2C Character List) from ("+source.toString()+") CONTENTS: ("+text.substring(0,text.length()-1)+")";
64 }
65
66 public void writeObject(marauroa.net.OutputSerializer out) throws IOException
67 {
68 super.writeObject(out);
69 out.write(characters);
70 }
71
72 public void readObject(marauroa.net.InputSerializer in) throws IOException, java.lang.ClassNotFoundException
73 {
74 super.readObject(in);
75 characters=in.readStringArray();
76
77 if(type!=TYPE_S2C_CHARACTERLIST)
78 {
79 throw new java.lang.ClassNotFoundException();
80 }
81 }
82 };
83
84
85