Source code: marauroa/net/MessageC2SChooseCharacter.java
1 /* $Id: MessageC2SChooseCharacter.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 /** This message indicate the server what of the available characters is chosen
19 * for the session to play.
20 * @see marauroa.net.Message
21 */
22 public class MessageC2SChooseCharacter extends Message
23 {
24 private String character;
25
26 /** Constructor for allowing creation of an empty message */
27 public MessageC2SChooseCharacter()
28 {
29 super(null);
30
31 type=TYPE_C2S_CHOOSECHARACTER;
32 }
33
34 /** Constructor with a TCP/IP source/destination of the message and the name
35 * of the choosen character.
36 * @param source The TCP/IP address associated to this message
37 * @param character The name of the choosen character that <b>MUST</b> be one
38 * of the returned by the marauroa.net.MessageS2CCharacters
39 * @see marauroa.net.MessageS2CCharacters
40 */
41 public MessageC2SChooseCharacter(InetSocketAddress source,String character)
42 {
43 super(source);
44
45 type=TYPE_C2S_CHOOSECHARACTER;
46 this.character=character;
47 }
48
49 /** This methods returns the name of the chosen character
50 @return the character name*/
51 public String getCharacter()
52 {
53 return character;
54 }
55
56 /** This method returns a String that represent the object
57 * @return a string representing the object.*/
58 public String toString()
59 {
60 return "Message (C2S ChooseCharacter) from ("+source.toString()+") CONTENTS: ("+character+")";
61 }
62
63 public void writeObject(marauroa.net.OutputSerializer out) throws IOException
64 {
65 super.writeObject(out);
66 out.write(character);
67 }
68
69 public void readObject(marauroa.net.InputSerializer in) throws IOException, java.lang.ClassNotFoundException
70 {
71 super.readObject(in);
72 character=in.readString();
73
74 if(type!=TYPE_C2S_CHOOSECHARACTER)
75 {
76 throw new java.lang.ClassNotFoundException();
77 }
78 }
79 };